home *** CD-ROM | disk | FTP | other *** search
/ Shareware Universe - The Gold Collection / Shareware Universe The Gold Collection.iso / ray / vivid2 / vivid.go < prev    next >
Encoding:
Text File  |  1996-04-19  |  92.6 KB  |  3,228 lines

  1. Vivid 2.0      March 14, 1992
  2.  
  3.               Copyright 1989-1992 by Stephen B. Coy
  4.  
  5.  
  6.                 Table of Contents
  7.  
  8.  
  9.         Introduction . . . . . . . . . . . . . . . . . .   2
  10.         Changes for Version 2.0. . . . . . . . . . . . .   3
  11.         Running Vivid. . . . . . . . . . . . . . . . . .   5
  12.         Statistics Display . . . . . . . . . . . . . . .   7
  13.         Legal Stuff. . . . . . . . . . . . . . . . . . .   9
  14.         Acknowledgements . . . . . . . . . . . . . . . .  11
  15.         Input File Format. . . . . . . . . . . . . . . .  13
  16.         Preprocessor . . . . . . . . . . . . . . . .  15
  17.         Studio . . . . . . . . . . . . . . . . . . .  17
  18.         Lights . . . . . . . . . . . . . . . . . . .  24
  19.         Surfaces . . . . . . . . . . . . . . . . . .  28
  20.             bump mapping . . . . . . . . . . . . . .  31
  21.             solid texture. . . . . . . . . . . . . .  33
  22.             Mandelbrot . . . . . . . . . . . . . . .  36
  23.         Geometric Primatives . . . . . . . . . . . .  37
  24.             sphere . . . . . . . . . . . . . . . . .  37
  25.             ring . . . . . . . . . . . . . . . . . .  38
  26.             polygon. . . . . . . . . . . . . . . . .  39
  27.             triangular patch . . . . . . . . . . . .  40
  28.             cone . . . . . . . . . . . . . . . . . .  41
  29.         Transformations. . . . . . . . . . . . . . .  42
  30.         Clipping . . . . . . . . . . . . . . . . . .  44
  31.         Support Programs . . . . . . . . . . . . . . . .  46
  32.         img2gif.exe. . . . . . . . . . . . . . . . .  46
  33.         paste.exe. . . . . . . . . . . . . . . . . .  50
  34.         up.exe . . . . . . . . . . . . . . . . . . .  51
  35.         down.exe . . . . . . . . . . . . . . . . . .  52
  36.         File Formats . . . . . . . . . . . . . . . . . .  53
  37.         Bibliography . . . . . . . . . . . . . . . . . .  54
  38.         Index. . . . . . . . . . . . . . . . . . . . . .  55
  39.     
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.                     1
  54.  
  55.  
  56.  
  57.  
  58.                 Introduction to Vivid 2.0
  59.  
  60.          Surprise!  Yes, 2.0 is finally here.  I'd like to appologize
  61.     to those of you who have been waiting for many months for this to
  62.     come out.  I've been busy doing my Master's thesis and, of
  63.     course, adding "just this one more feature." A few bugs were
  64.     squashed in the process although I'm sure that new ones have been
  65.     breeding in the walls just waiting until this release.  Even with
  66.     the bugs I still consider Vivid to be one of the finest ray
  67.     tracers (I've) ever written. 
  68.  
  69.          In the archive you received should be this document, the
  70.     Vivid executable, some sample input files, and tools for
  71.     processing the image after it has been generated.  Vivid.exe has
  72.     been compiled to run on any MS-DOS based system with a 286 or
  73.     better and a math coprocessor.  Ray tracing can be extremely slow
  74.     and anything less is really not worth it.  If, however, you don't
  75.     believe me feel free to write and I'll send you a copy compiled
  76.     for an bare 8086.  I hope you don't plan on using your PC in the
  77.     next month.  Back to the 286/287 version.  This version also
  78.     contains a DOS extender allowing Vivid to take advantage of any
  79.     extended memory you may have.  For those of you that still want
  80.     something better I also have 386 versions available.  See the
  81.     Legal Stuff section for more info. 
  82.  
  83.          The rest of this document explains the details of how to run
  84.     Vivid and the tools and how to construct an input file.  I
  85.     recommend that you print out this file and a couple of the sample
  86.     input files when first learning Vivid.  An example is worth a
  87.     thousand words, or at least the paper it's printed on. 
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.                     2
  112.  
  113.  
  114.  
  115.  
  116.               (Most of the) Changes for Version 2.0
  117.  
  118.  
  119.          I learned to spell Mark VandeWettering's name correctly. 
  120.     Sorry about version 1.0 Mark. 
  121.  
  122.          Inside/outside problems have been resolved eliminating the
  123.     need to have spheres with negative radii or worry about clockwise
  124.     vs counter-clockwise polygons. 
  125.  
  126.          Polygon patches are a lot healthier. 
  127.  
  128.          I plugged my brain back in.  The description of fuzzy
  129.     spheres given in the 1.0 docs is wrong.  But it's better now. 
  130.  
  131.          When using the depth of field option a new "samples"
  132.     parameter has been added to allow you to control the number of
  133.     rays per pixel used. 
  134.  
  135.          Spherical light sources also allow the "samples" parameter
  136.     to determine the number of shadow rays shot toward them. 
  137.  
  138.          There is no longer a limit on the number of lights except
  139.     for memory and your patience.  The limit was 20 but this info
  140.     never made it into the docs for version 1.0.  The limit on number
  141.     of objects has also been removed although due to the operating
  142.     system an effective limit of about 2000 objects still remains. 
  143.     The DOS extender version is limited only by memory. 
  144.  
  145.          The number of objects contained within a bounding box may
  146.     now be specified.  The default, 4, is equal to the prior, fixed
  147.     value.  This can be specified by adding
  148.         bunching 6
  149.     to the studio structure.  Changing this value will affect the
  150.     performance of the automatic bounding box construction.  Results
  151.     are image dependent but I think that 4 is a good default value. 
  152.  
  153.          A bug in the camera model caused the image to become
  154.     distorted when the up vector given in the studio structure wasn't
  155.     perpendicular to the direction of view.  It has been fixed. 
  156.  
  157.          The traditional flat projection model has been joined by not
  158.     one, not just two, but by three other projection models,
  159.     spherical, othographic and parallax.  See the section on the
  160.     studio structure for details. 
  161.  
  162.          The input file format has been changed to eliminate the need
  163.     for semicolons and equals signs.  In order to be compatable with
  164.     the old file format, they are still accepted but are now treated
  165.     just as a space would be treated. 
  166.  
  167.          A quick-render mode has been added to help speed up
  168.  
  169.                     3
  170.  
  171.  
  172.  
  173.     previews. 
  174.  
  175.          Simple math operations are now supported by the parser. 
  176.     These operations are supported on numbers and on vectors (rgb
  177.     triples and xyz coordinates).  The following is a list of the
  178.     operations supported.  Vectors operations supported include cross
  179.     product, addition, subtraction, scaling, and dot product. 
  180.     Numerical operations include multiplication, division, addition,
  181.     subtraction and exponentiation.  Sine, cosine, tangent, arcsine,
  182.     arccosine, arctangent and square root functions are also
  183.     supported. 
  184.  
  185.          Cylinders can now be specified by giving a cone a single
  186.     radius parameter. 
  187.  
  188.          Preprocessor is here.  include files, defines, undefs and
  189.     lack of fixed colors which are now replaced with color.vc. 
  190.  
  191.          Global transformations are now supported.  Together with
  192.     include files this should make scene modeling much easier. 
  193.  
  194.          Primitives can now be clipped by planes, spheres or cone
  195.     allowing easier generation of more complex models. 
  196.  
  197.          The background can have a palette mapped to it rather than
  198.     just having a single color. 
  199.  
  200.          A new bunch of command line switches are now supported. 
  201.     Typing vivid on the command line without any arguements will give
  202.     you a listing of them. 
  203.  
  204.          The keyword "noise" is now "turbulence" to better follow the
  205.     literature. 
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.                     4
  228.  
  229.  
  230.  
  231.  
  232.                   Running Vivid
  233.  
  234.          Vivid input files use the extension .v and the output files
  235.     use .img.  With the preproccessor in Vivid, include files are
  236.     also supported.  These may have any extension.  The syntax for
  237.     including a file into your input file is:
  238.     
  239.         #include filename
  240.     
  241.  
  242.          Include files may have any extension you choose.  The
  243.     following is a list of the file extensions that I regularly use. 
  244.     If we all use the same convention it should make things easier
  245.     for trading input files.  Feel free come up with your own
  246.     conventions if that suits you better. 
  247.     
  248.         .v      Main input file for an image.  Required.
  249.         .img    24-bit output file.
  250.         .map    palette file for img2gif or background mapping.
  251.         .vc     include file with color definitions.  See color.vc.
  252.         .vo     include file with object definition.
  253.         .vs     include file with surface definitions.
  254.     
  255.  
  256.          The .img files produced by Vivid are full 24-bit color.  The
  257.     details of their format are explained later in this document. 
  258.     Since most systems can't display 24-bit graphics I've included a
  259.     tool to convert the .img files into .gif files which can be
  260.     displayed using vpic or cshow.  This tool is called img2gif.  Its
  261.     workings are also detailed later.  In general the procedure for
  262.     generating an image will look like this:
  263.     
  264.     1)  Create an input file, test.v, with your favorite text editor.
  265.     2)  Run Vivid.
  266.         C>vivid test
  267.     3)  Wait until done.  This can take from a few minutes to a
  268.         couple of days depending on the complexity of the image
  269.         and the speed of your machine.  This is a good time to
  270.         raid the fridge.
  271.     4)  Convert the result, test.img, into a .gif file.
  272.         C>img2gif -m -d test
  273.         The -m flag tells img2gif to use median cut to determine
  274.         the palette.  The -d flags turns on Floyd-Steinberg
  275.         dithering.
  276.     5)  View the image.
  277.         C>vpic test.gif
  278.     
  279.     
  280.  
  281.          Because of the way I implemented the preprocessor Vivid
  282.     creates a temporary file on the disk called xyzzy.v.  At this
  283.     time, Vivid does not delete the file after it is done using it. 
  284.  
  285.                     5
  286.  
  287.  
  288.  
  289.     The reason I leave this is that it is sometimes useful to look at
  290.     when trying to figure out what the preprocessor is doing with
  291.     your input definition.  Feel free to delete it at any time. 
  292.  
  293.                     
  294.  
  295.          Vivid supports a number of command line flags.  These flags
  296.     allow you to change the operation of the program without changing
  297.     the input file.  The following command line flags are now
  298.     supported:
  299.     
  300.         -s      Run in silent mode, ie no statistics display.
  301.         -r      Resume.
  302.         -i x y  Set image size to x by y pixels.
  303.         -n      No_shadows, same as studio flag.
  304.         -d #    Set maximum recursion depth value
  305.         -a mode Set antialias mode.  Valid modes are: none,
  306.             quick, corners and adaptive.  Since I can't type
  307.             I've made it so that you only have to give the
  308.             first letter of the mode for it to work.
  309.         -p      Don't use the preprocessor.
  310.     
  311.  
  312.          Vivid has the ability to resume the generation of an
  313.     interrupted image.  If during image generation you need to stop,
  314.     hitting ctrl-C or ctrl-BREAK will cause Vivid to stop at the end
  315.     of the next scan line.  This may be up to a few minutes for a
  316.     slow image.  This only works if statistics are enabled (the
  317.     default).  Later, the image generation may be resumed by using
  318.     the -r flag on the command line. 
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338.  
  339.  
  340.  
  341.  
  342.  
  343.                     6
  344.  
  345.  
  346.  
  347.  
  348.                    Statistics
  349.  
  350.  
  351.          Surprisingly enough some people are curious about the
  352.     statistics that Vivid displays while processing.  Somehow they
  353.     actually got the idea that the numbers may contain useful
  354.     information if only they were documented somewhere.  The secret
  355.     is out.  They don't mean a thing.  I just put them in there
  356.     because I like watching them change while I'm waiting for the
  357.     image to generate.  Sorry to break your bubble.  OK, fine, I'm
  358.     joking, happy now?
  359.  
  360.          When you run Vivid it displays the current version number
  361.     and the copyright notice.  It then displays the filename of the
  362.     input files as the preprocessor digests them.  Next a running
  363.     total of lights and primitives is displayed as the parser reads
  364.     the preprocessed input file.  Once the file is completely read in
  365.     the automagic bounding box code is called.  As it generates
  366.     bounding boxes you see the number of primitives climb.  Upon
  367.     completion of the bounding box generation the scene extent is
  368.     displayed.  This is the minimum and maximum values in each axis
  369.     for all the primitives.  At this time the first scan line is
  370.     starting to be rendered.  When it is done the screen will clear
  371.     and a full display of current statistics will be displayed.  The
  372.     meanings for each of the numbers will now be described in
  373.     glorious detail bereft of all attempts at obfuscation.  I hope
  374.     this makes sense. 
  375.  
  376.          The resolution is the size of the final image in pixels. 
  377.     The line display next to it shows the progress of the ray tracer. 
  378.     For example, if you where generating an image 320 pixels wide and
  379.     200 pixels tall the resolution would display 320x200
  380.     (unbelievable!) and the line value would go from 0 to 200.  In
  381.     quick mode this number will increment by 6 instead of 1. 
  382.  
  383.          The next four lines contain information about the number of
  384.     rays cast.  Eye rays are the rays cast from the viewpoint out
  385.     into the scene.  Reflected rays are those generated by a specular
  386.     surface and refracted rays are those generated by transparent
  387.     surfaces.  The total is just the sum of these rays.  If your
  388.     input file doesn't have any reflective or transparent surfaces
  389.     these numbers will stay 0. 
  390.  
  391.          The next section contains information about shadow rays. 
  392.     Shadow rays are the rays shot from the point of intersection
  393.     toward each light in order to determine if there are any other
  394.     primitives in the scene blocking the light (casting a shadow). 
  395.     Vivid uses a shadow cache to try and speed up this process. 
  396.     Cache hits signify an instance when the cached object was found
  397.     to cast a shadow and no ray was cast.  The cache percentage is
  398.     just the number of hits divided by the number of shadow rays. 
  399.  
  400.  
  401.                     7
  402.  
  403.  
  404.  
  405.          The next number is the average number of rays cast per
  406.     pixel.  This number can give you a fair idea of just how hard the
  407.     ray tracer is working to generate the image.  With no
  408.     antialiasing, reflection, or refraction this number should be
  409.     1.0.  Adaptive antialiasing can push this as high as 16 depending
  410.     on the amount of extra work it does.  Reflected and refracted
  411.     rays will make this even higher.  Using the quick mode this
  412.     number may go to as low as .066 or so.  When this number is less
  413.     than 1 that means that the ray tracer is guessing at some of the
  414.     pixels instead of actually casting a ray for them. 
  415.  
  416.          The average queues per ray value has to do with the bounding
  417.     scheme.  The automatic bounding box generator creates a tree-like
  418.     heirarchy of bounding boxes for the system to test each ray
  419.     against.  If a box is intersected by a ray then the objects in
  420.     the bounding box (either other bounding boxes or primitives) are
  421.     entered into the priority queue for further intersection testing. 
  422.     The "bounds checked" number shows how many bounding box
  423.     intersection tests were performed.  The "queue inserts" number
  424.     shows how many object passed the bounds check and were put into
  425.     the priority queue.  The "queue resets" number displays the total
  426.     number of times the priority queue was reset.  This should be
  427.     equal to the total number of rays plus the number of shadow rays
  428.     plus the number of cache hits.  Don't ask why, it just will be. 
  429.     The "max queue size" number shows the maximum number of objects
  430.     in the queue during the rendering. 
  431.  
  432.          The final number, the max recursion depth, shows the maximum
  433.     number of levels deep the ray tracer had to go while rendering
  434.     the image.  The number after the slash is the max depth it is
  435.     allowed to go. 
  436.  
  437.  
  438.  
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.                     8
  460.  
  461.  
  462.  
  463.  
  464.                    Legal Stuff
  465.  
  466.         Vivid is Copyright 1989-1992 by
  467.         Stephen B. Coy
  468.         All Rights Reserved.
  469.  
  470.          You are free to redistribute this package in its entirety. 
  471.     In doing so you may charge no more than a nominal fee for
  472.     duplication.  No part of this package may be included as part of
  473.     a commercial package without explicit written permission.  If you
  474.     have any questions about commercial distribution of Vivid or its
  475.     tools I can be contacted at:
  476.     
  477.         Stephen Coy
  478.         Vivid Software
  479.         15205 NE 13th Pl.  #2904
  480.         Bellevue, WA  98007
  481.         (206) 641-8615
  482.     
  483.         INTERNET:    coy@ssc-vax.boeing.com or
  484.                  uw-beaver!ssc-vax!coy
  485.         CompuServe:  70413,136
  486.     
  487.  
  488.          Originally I thought of distributing Vivid via shareware but
  489.     I seriously dislike the guilt games most shareware authors
  490.     include.  So, I've decided to try beggarware.  Here's the
  491.     product.  Use it.  If you like it I'd be very happy if you'd sent
  492.     a check for $30.  If you think $30 is out of line, send less (or
  493.     more) or beer.  If you don't think Vivid is worth diddly at least
  494.     send a postcard explaining why you don't like it.  If you want
  495.     the 386 versions you'll have to register at the $50 level.  Sorry
  496.     about that but times are tough and compilers aren't cheap. 
  497.     Anyway that's about the price of an average game lately so I
  498.     don't think it's too far out of line.  As is usual I will also
  499.     accept severe sob stories, beer, software (nothing pirated, thank
  500.     you), barter goods, and young women instead of money.  The 386
  501.     diskette contains versions of Vivid compiled with both the
  502.     Zortech and the Intel compilers giving you a choice of DOS
  503.     extenders to work with.  The Intel version is DPMI compliant and
  504.     has the advantage of supporting virtual memory allowing you to
  505.     allocate up to 128Mb of disk space as memory for those seriously
  506.     huge models.  The Zortech version is DPMI, VCPI and XMS
  507.     compatible and takes up less space.  It also seems to be able to
  508.     find about 500K more memory than the Intel version but doesn't
  509.     directly offer virtual memory support.  If another DPMI host
  510.     which supports virtual memory is active, Windows 3.0 running in
  511.     386 enhanced mode for instance, then the Zortech version can take
  512.     advantage of it. 
  513.  
  514.          Whether you send anything or not I would like to hear about
  515.     any suggestions or bugs.  Of course requests accompanied by money
  516.  
  517.                     9
  518.  
  519.  
  520.  
  521.     will tend to get higher priority.  I will answer all mail and
  522.     email even though I may be a bit slow at times.  Email tends to
  523.     get the fastest response.  If you have tried to contact me and
  524.     not gotten a response please try again.  If you still don't get a
  525.     response you might have to resort to US Mail. 
  526.  
  527.          For those of you into BBSing I can be contacted via any of
  528.     the ADEnet nodes.  ADEnet is a network of BBSs primarily
  529.     dedicated to providing professional quality support for AutoCAD
  530.     and other CAD programs.  In addition there is also an animation
  531.     and rendering conference where questions about Vivid, or graphics
  532.     in general, will be answered.  I usually log in on a daily basis
  533.     so turn around is quite quick.  Another BBS I log into a lot is
  534.     TurboTech.  Ray Johnson, TurboTech's sysop and the author of
  535.     TurboCit, has provided a room for ray trace discussions and has
  536.     plenty of disk space for images.  Check out the conversations,
  537.     too.  The BBS attracts some interesting people.  I also frequent
  538.     CompuServe's COMART forum for those of you with deeper pockets. 
  539.  
  540.          Ray Johnson's Turbo Tech BBS can be reached at
  541.     (206)362-6828. 
  542.  
  543.          Alacrity Design & Engineering Network (ADEnet)
  544.  
  545.  
  546.          ADEnet serves the design and engineering communities by
  547.     making information useful to them widely available.  This is done
  548.     in three ways: the ADEnet message conferences, the sharing of
  549.     programs and data files across ADEnet and the dissemination of
  550.     industry news and press releases. 
  551.  
  552.                   ADEnet Member Listing
  553.  
  554.  
  555.          The following is a listing of the current ADEnet Member
  556.     BBSs.  Each ADEnet Member is an independant BBS operated by a
  557.     local sysop. 
  558.     Alacrity Software BBS    206-643-5477 Bellevue, WA       DUAL (14.4)
  559.     The Graphics Alternative 510-524-2780 El Cerruto, CA     DUAL (14.4)
  560.     Off Broadway             510-547-5264 San Francisco, CA  V32
  561.     PC-AUG BBS               602-952-0638 Phoenix, AZ        DUAL (9600)
  562.     Mind Image BBS           612-781-1720 Minneapolis, MN    v22, MNP5
  563.     LABB                     717-394-1357 Lancaster, PA      v22, MNP5 [%]
  564.     AEC-ONLINE               818-360-7022 Los Angeles, CA    v22
  565.     The University BBS       908-544-8193 Shrewsbury Twp, NJ DUAL (14.4)
  566.     AZCAD BBS              +61-3-481-6873 Australia          v32bis
  567.     
  568.  
  569.          Each of the listings has the BBS name and it's (primary)
  570.     phone number followed by the location.  At the end of listing is
  571.     the highest allowable bits per second (bps) and protocol. 
  572.     DUAL - US Robotics Dual Standard supporting HST and v.32/v.42bis
  573.     HST  - US Robotics Courier HST
  574.  
  575.                     10
  576.  
  577.  
  578.  
  579.     v32  - Industry standard v.32/v.42bis supporting upto 9600 bps
  580.     v32b - Industry standard v.32bis/v.42bis supporting upto 14.4k bps
  581.     v22  - Industry standard v.22 supporting upto 2400 bps
  582.     MNP5 - Indicates support Microcom Network Protocol Class 5
  583.     v42b - Indicates support for CCITT v.42bis
  584.     
  585.     [*] CAD/Engineering Services BBS accepts calls between 22:00-05:00 CST.
  586.     [%] LABB is a multiline system, of which only the main line is listed.
  587.     
  588.  
  589.          The following is a listing of the current ADEnet message
  590.     conferences. 
  591.            Conference  Description
  592.            --------------------------------------------------------
  593.            Autodesk    Autodesk product support
  594.            A/E/C       Architectual, Engineering and Construction
  595.            CAD/CAM     Manufacturing, NC Programming
  596.            Civil       Civil engineering
  597.            CompuGFX    Computer graphics, rendering and animation
  598.            DTP         Desktop publishing
  599.            ForSale     Buy & Sell used equipment, job listings
  600.            Generic     Generic Software product support
  601.            GIS         Geographical information services
  602.            uStation    Integraph Microstation support
  603.            News        Industry news and press releases
  604.            Public      Network wide (ADEnet) general conference
  605.            TechTalk    Technical hardware and software discussions
  606.     
  607.  
  608.  
  609.                  Joining ADEnet
  610.  
  611.  
  612.          If you are the system operator of a BBS and interested in
  613.     joining ADEnet, please download ADENET.ZIP.  Within is a more
  614.     detailed introduction to ADEnet, an application form, and all of
  615.     the necessary information and data files you'll need. 
  616.  
  617.          ADEnet currently supports PC-Relay, QWK/REP, and FidoNet's
  618.     echomail message networking protocols.  Alacrity Software BBS
  619.     serves as the ADEnet hub for nodes using either PC-Relay or
  620.     QWK/REP.  The University BBS acts as ADEnet's "bridge" to nodes
  621.     using echomail. 
  622.  
  623.  
  624.  
  625.  
  626.  
  627.  
  628.  
  629.  
  630.  
  631.  
  632.  
  633.                     11
  634.  
  635.  
  636.  
  637.  
  638.                 Acknowledgements
  639.  
  640.          First on the list I must thank Mark VandeWettering for his
  641.     raytracer MTV.  Some pieces of Vivid have been lifted directly
  642.     from MTV's code.  Hopefully, I only took the bug-free ones.  I'd
  643.     like to thank Mike Thompson for his various contributions both
  644.     technical and fermented.  Thanks to Gregor Harrison for a lot of
  645.     help understanding lex & yacc.  I still am somewhat confused but
  646.     I like it that way.  Thanks to Jason Osgood of ADEnet for
  647.     providing a forum for my rantings about Vivid.  Thanks to Drew
  648.     Wells for encouraging me to join CompuServe.  And thanks to all
  649.     those folks who unwittingly helped Vivid through their postings
  650.     to usenet.  Finally, I'd like to thank all of you who took time
  651.     to send comments (and images and beer and money) for version 1. 
  652.     Coming home to a nice letter and a check in the mail rather than
  653.     just bills makes the whole week go better.  Thank you. 
  654.     
  655.     GIF is a trademark of CompuServe
  656.     MS-DOS is a trademark of Microsoft
  657.     
  658.     
  659.  
  660.  
  661.  
  662.  
  663.  
  664.  
  665.  
  666.  
  667.  
  668.  
  669.  
  670.  
  671.  
  672.  
  673.  
  674.  
  675.  
  676.  
  677.  
  678.  
  679.  
  680.  
  681.  
  682.  
  683.  
  684.  
  685.  
  686.  
  687.  
  688.  
  689.  
  690.  
  691.                     12
  692.  
  693.  
  694.  
  695.  
  696.                 Input File Format
  697.  
  698.          One thing to keep in mind while creating Vivid input files
  699.     is that Vivid's parser is case sensitive.  Macros (see
  700.     preprocessor section) are also case sensitive. 
  701.  
  702.          Vivid uses a right-handed coordinate system for defining the
  703.     location of objects in space.  A right-handed coordinate system
  704.     can be visualized as having the x axis pointing to the right, the
  705.     y axis pointing into the screen and the z axis pointing up.  Each
  706.     object in a scene file will be defined as having a location in
  707.     space defined by an x, y, z triple in this coordinate system. 
  708.  
  709.          Colors are defined by an r, g, b triple where each component
  710.     generally falls in the range 0..1.  To make picking colors easier
  711.     Vivid includes the file color.vc which contains a few dozen
  712.     predefined colors.  Their names and rgb values can be had by
  713.     viewing or printing color.vc.  If this file is #included at the
  714.     top of you input file these names can be used anywhere an rgb
  715.     triple is called for. 
  716.  
  717.          Simple math operations are now supported by the parser. 
  718.     These operations are supported on numbers and on vectors (rgb
  719.     triples and xyz coordinates).  The following is a list of the
  720.     operations supported.  Vectors operations supported include cross
  721.     product, addition, subtraction, scaling, and dot product. 
  722.     Numerical operations include multiplication, division, addition,
  723.     subtraction and exponentiation.  Sine, cosine, tangent, arcsine,
  724.     arccosine, arctangent and square root functions are also
  725.     supported. 
  726.     
  727.         Vector ops
  728.         ----------
  729.         a b c cross x y z       cross product, yields a vector
  730.         a b c dot x y z         dot product, yields a number
  731.         a b c + x y z           vector addition, yields a vector
  732.         a b c - x y z           vector subtraction, yields a vector
  733.         a b c * n               scale a vector by n
  734.         a b c / n               scale a vector by 1/n
  735.         -(a b c)                negate a vector
  736.     
  737.         Numeric ops
  738.         -----------
  739.         sin(x), cos(x), tan(x)  trig functions
  740.         asin(x), acos(x), atan(x)
  741.         sqrt(x)                 returns square root of x
  742.         pow(x y)                returns x to the yth power
  743.         *, /, +, -              normal mathematical operations
  744.     
  745.  
  746.          It should be noted that these operations introduce some
  747.     ambiguity to the input language.  This problem is aggravated by
  748.  
  749.                     13
  750.  
  751.  
  752.  
  753.     the fact that the parser can only look one token ahead when it
  754.     tries to decide how to treat its current input.  I encourage you
  755.     to avoid any such problems by generously using parantheses to
  756.     eliminate any possible ambiguity in your equations.  For example:
  757.     
  758.         n * a b c can result in either
  759.         (n*a) b c or
  760.         (n*a) (n*b) (n*c)
  761.         depending on how the parser is feeling that day.
  762.     
  763.     
  764.  
  765.          If you really want to I'm sure that you could figure out
  766.     what the parser is doing but that may change in the future so
  767.     save yourself the trouble and just add the parentheses. 
  768.  
  769.          Comments can also be included in the input file.  Like
  770.     comments in computer programs, comments in Vivid input files are
  771.     ignored by the input parser.  Comments in Vivid use the same
  772.     syntax as comments in C++ do.  Multi-line comments start with /*
  773.     and end with */.  Anything between the comment delimeters is
  774.     ignored.  Single line comments start with // and end at the end
  775.     of the line.  For example:
  776.     
  777.     /*      This is a comment
  778.         which spans multiple lines  */
  779.     
  780.     //      This is a single line comment
  781.     
  782.     
  783.  
  784.          Comments should be used as notes in your input files to help
  785.     remind you or anyone else reading the file what the input is
  786.     trying to do.  Comments can also be used to block out part of the
  787.     input file while you are setting it up to help speed up test
  788.     renderings. 
  789.  
  790.          Normally an input file will be made up of a studio
  791.     definition which describes the image size, antialiasing and
  792.     viewpoint followed by the definitions for lights, surfaces, and
  793.     objects.  Object definitions only deal with the geometry of the
  794.     object.  The surface characteristics (color, shine) of the object
  795.     are taken from the last surface definition preceding the object. 
  796.  
  797.  
  798.  
  799.  
  800.  
  801.  
  802.  
  803.  
  804.  
  805.  
  806.  
  807.                     14
  808.  
  809.  
  810.  
  811.  
  812.                   Preprocessor
  813.  
  814.  
  815.          To make writing input files easier, Vivid's parser also has
  816.     a preprocessor.  Currently, the preprocessor only supports two
  817.     functions, the definition of macros and support for include
  818.     files.  Because of the way I implemented the preprocessor Vivid
  819.     creates a temporary file on the disk called xyzzy.v.  (Didn't I
  820.     already mention this? deja vu) At this time, Vivid does not
  821.     delete the file after it is done using it.  The reason I leave
  822.     this is that it is sometimes useful to look at when trying to
  823.     figure out what the preprocessor is doing with your input
  824.     definition.  Feel free to delete it at any time. 
  825.  
  826.          Macros allow you to associate a name with a string of
  827.     characters.  When the parser sees the name in the input file it
  828.     will substitute the appropriate string before continuing.  A
  829.     simple example of this is the color definitions in the file
  830.     color.vc.  In color.vc the colors white and blue are defined like
  831.     this:
  832.     
  833.     #define blue    (0 0 1)
  834.     #define white   (1 1 1)
  835.     
  836.  
  837.          Once defined you can then use the word "white" wherever you
  838.     would normally have to type (1 1 1).  For example, to create a
  839.     blue surface with a white highlight you could then do this:
  840.     
  841.     surface {
  842.         diffuse blue
  843.         shine 20 white
  844.     }
  845.     
  846.  
  847.          Macro names must start with a letter and may contain
  848.     letters, numbers, and the underscore character "_".  Macro names
  849.     are case sensitive.  Note than in the examples I define the
  850.     colors with parentheses around the rgb values.  This is not
  851.     required but helps eliminate any potential parser problems as
  852.     mentioned in the section on the parser's math ability.  You can
  853.     undefine a macro using the #undef keyword. 
  854.     
  855.     #undef blue
  856.     
  857.  
  858.          If you define the same macro more than once the old values
  859.     are put onto a stack and the newest one will always be used.  If
  860.     you then undefine the macro, only the newest one will be deleted
  861.     and the next newest definition will then be active.  If you want
  862.     to define a macro that is longer than one line you have to use
  863.     the backslash, "\", as a continuation character. 
  864.  
  865.                     15
  866.  
  867.  
  868.  
  869.     
  870.     #define BLUE_PLASTIC                    \
  871.         surface {                       \
  872.             diffuse blue            \
  873.             shine 20 white          \
  874.         }
  875.     
  876.  
  877.          Notice that the last line does not have a backslash after
  878.     it.  Once defined you can then just use the name BLUE_PLASTIC in
  879.     the input file wherever you would normally type in the whole
  880.     surface declaration. 
  881.  
  882.          The other preprocessor directive is #include.  This allows
  883.     you to include other files into your input file.  Look at the
  884.     sample input files and notice that almost the first thing in the
  885.     file is a line like:
  886.     
  887.     #include color.vc
  888.     
  889.  
  890.          This causes the parser to read in the file color.vc which
  891.     defines a standard set of colors for use in creating input files. 
  892.     Using Dan Farmer's color editor it is quite easy to create new
  893.     colors to add to this file.  The include command is also useful
  894.     for including objects into your scene.  Combined with the
  895.     transformation commands this will allow you to create objects as
  896.     seperate files and inlcude them into the scene at any location
  897.     and orientation.  You may also inlcude multiple copies of an
  898.     object. 
  899.  
  900.  
  901.  
  902.  
  903.  
  904.  
  905.  
  906.  
  907.  
  908.  
  909.  
  910.  
  911.  
  912.  
  913.  
  914.  
  915.  
  916.  
  917.  
  918.  
  919.  
  920.  
  921.  
  922.  
  923.                     16
  924.  
  925.  
  926.  
  927.  
  928.                    The Studio
  929.  
  930.          The studio structure in the scene file defines all those
  931.     things that are neither lights, objects or clips.  This includes
  932.     the resolution of the final image, the location of the camera
  933.     (viewpoint), the direction the camera is pointing, the background
  934.     color, and various rendering options.  Some of the options have
  935.     default values.  These are the values these options will take on
  936.     if they are left out of the studio definition.  The studio
  937.     definition looks like this:
  938.     
  939.     studio {
  940.         from x y z
  941.         at x y z
  942.         up x y z
  943.         angle ang
  944.         resolution i j
  945.         start line
  946.         stop line
  947.         aspect asp
  948.         projection mode
  949.     
  950.         ambient acolor
  951.         background bcolor
  952.         haze density
  953.     
  954.         antialias mode
  955.         threshold dist
  956.         jitter
  957.     
  958.         aperture size
  959.         focal_length dist
  960.         samples n
  961.     
  962.         no_shadows
  963.         no_exp_trans
  964.         caustics
  965.     
  966.         depth max_depth
  967.         bunching n
  968.     }
  969.     
  970.     "from" is the location of the camera. 
  971.  
  972.     "at" is where in the scene the camera is pointed. 
  973.  
  974.     "up" is a vector pointing up, usually 0 0 1.  This can be
  975.         played with to roll the image around the axis of
  976.         the camera. 
  977.  
  978.     "angle" is the field-of-view angle given in degrees. 
  979.  
  980.  
  981.                     17
  982.  
  983.  
  984.  
  985.     "resolution" is the size of the image in pixels, i pixels
  986.         across and j pixels down.  This can also be
  987.         controlled from the command line using the -i
  988.         switch. 
  989.  
  990.     "start" and "stop" allow you to start and stop the
  991.         rendering at the specified line numbers.  I use
  992.         this for testing new input files and isolating
  993.         bugs.  Those of you with networks might want to
  994.         consider using this to split up an image for
  995.         rendering on multiple computers.  After the
  996.         sections are done you can then use paste.exe to
  997.         glue them together.  Currently there is a problem
  998.         with using start and the resume (-r) flag.  Avoid
  999.         the combination. 
  1000.  
  1001.     "aspect" is the aspect ratio of the screen.  This is the
  1002.         ratio of width to height of the screen you are
  1003.         rendering your images for.  I've found that my
  1004.         Nec 3D has an aspect ratio of about 4/3 and that
  1005.         my Amiga 1084 has an aspect ratio of about 1.2. 
  1006.         To determine the proper aspect ratio for your
  1007.         screen measure the width and height of a screen
  1008.         image.  The aspect ratio of your screen can be
  1009.         found by dividing the width by the height. 
  1010.         Determining the correct aspect ratio of your
  1011.         screen will insure that circles come out looking
  1012.         like circles instead of ovals.  Remember, aspect
  1013.         ratio should the the width/height ratio of the
  1014.         displayed image regardless of the image
  1015.         resolution.  Together with the resolution these
  1016.         are used to determine the aspect ratio of the
  1017.         pixels. 
  1018.  
  1019.     "projection" controls how the 3d world is mapped onto the
  1020.         2d screen.  The default is "flat".  This is the
  1021.         standard perspective projection you've all come
  1022.         to know and love.  "spherical" projection
  1023.         produces an effect somewhat like a fisheye lens. 
  1024.         Things can look pretty strange.  Unique to the
  1025.         "spherical" mode is the field of view angle can
  1026.         be greater than 180 degrees.  Try a 360 degree
  1027.         panorama some time.  The "orthographic"
  1028.         projection mode produces an image where all the
  1029.         eye rays are parallel to each other.  For this
  1030.         mode the "angle" parameter has no meaning and is
  1031.         replaced with a "width" parameter.  Width defines
  1032.         how wide the screen is in the world coordinate
  1033.         system.  Generally, I think that this mode is
  1034.         useless but it was easy to code so why not? The
  1035.         final mode is the "parallax" projection mode. 
  1036.         This produces a 2-point projection instead of a
  1037.         3-point projection like the "flat" mode.  In the
  1038.  
  1039.                     18
  1040.  
  1041.  
  1042.  
  1043.         "parallax" mode, all vertical lines stay vertical
  1044.         on the screen.  This was implemented specifically
  1045.         for architectural renderings but is sometimes
  1046.         useful in other contexts.  Note that "vertical"
  1047.         is defined by the direction of the up vector. 
  1048.  
  1049.     "ambient" is the color of the light that is everywhere in
  1050.         the image.  In "the real world" when light
  1051.         strikes diffuse surfaces such as walls, some of
  1052.         it is scattered back into the room.  This is why
  1053.         you can still see under a desk even though no
  1054.         light is shining directly underneath it.  Most
  1055.         ray tracers, including Vivid, can't handle this
  1056.         diffuse interreflection.  But, all hope is not
  1057.         lost.  To fake diffuse interreflection Vivid
  1058.         allows you to set an ambient light value.  This
  1059.         acts like a light that is shining in every
  1060.         direction at once and does not cast any shadows. 
  1061.         For an inside scene values of about .2 .2 .2 seem
  1062.         to work well.  Outside scenes look a bit more
  1063.         realistic with a higher ambient value because of
  1064.         the scattering of light the atmosphere does. 
  1065.         Most ray traced images that you will see just
  1066.         have the ambient value set to 0 0 0 or black. 
  1067.         This produces the sharpest contrasts and gives
  1068.         the image a super-real effect.  The default value
  1069.         for ambient is 0 0 0. 
  1070.  
  1071.     "background" is the color that will be returned if no
  1072.         objects are hit while tracing a ray.  Popular
  1073.         choices are black and sky_blue.  If haze is
  1074.         defined then this is the color of the haze.  (see
  1075.         below) The background color defaults to black. 
  1076.         Alternatively you can do the following:
  1077.         
  1078.             background {
  1079.                 palette.map
  1080.                 up x y z
  1081.             }
  1082.         
  1083.          This produces a graduated background using the
  1084.         colors in the file palette.map.  The file can
  1085.         have any name but is required to have the .map
  1086.         extension.  The file is the same format as the
  1087.         img2gif palette files.  The first color in the
  1088.         file is the color that will appear in the
  1089.         direction of the up vector.  If no up vector is
  1090.         specified then the up vector from the studio
  1091.         structure will be used. 
  1092.  
  1093.     "haze" is the density of the fog or haze in the scene. 
  1094.         The haze density defaults to 0.  This means that
  1095.         there is no haze.  A value of .5 means that for
  1096.  
  1097.                     19
  1098.  
  1099.  
  1100.  
  1101.         every unit a ray travels, half of its color is
  1102.         determined by the background color.  This
  1103.         function is exponential, ie if the haze density
  1104.         is given as .5 the color of a ray going 1 unit
  1105.         will be .5 times the color of the object it hits
  1106.         and .5 times the background color.  A ray going 2
  1107.         units will be .25 the color of the object and .75
  1108.         times the background color.  For most images this
  1109.         parameter can be ignored and the default value of
  1110.         0 used. 
  1111.  
  1112.     "antialias" determines whether or not antialiasing is
  1113.         performed and what type is used.  This can also
  1114.         be controlled from the command line using the -a
  1115.         switch.  The valid modes are:
  1116.  
  1117.         none -- Do one ray per pixel, right through the
  1118.         center.  Results are blocky but relatively quick. 
  1119.         This is the default. 
  1120.         quick -- This does a subsampling approximation of the
  1121.         image.  In areas of even color the most speedup
  1122.         is gained.  This is the fastest mode but the
  1123.         results are not useful for much more than test
  1124.         images.  At best (ie on a blank image) this
  1125.         should be about 15 times faster than the above
  1126.         mode.  In general I notice about a 3-5 times
  1127.         speedup.  This is a great mode for doing test
  1128.         renderings. 
  1129.         corners -- Shoot a ray at each corner of the pixel
  1130.         and average the results.  Since the corners are
  1131.         shared by adjoining pixels this means about one
  1132.         ray per pixel.  The results are almost as quick
  1133.         as none but usually have a better look. 
  1134.         Effectively this is the same as running a
  1135.         smoothing filter over the image. 
  1136.         adaptive -- Rays are shot at the corners of the
  1137.         pixel.  If they are within a certain threshold of
  1138.         each other the program moves on to the next
  1139.         pixel.  If they differ by more than the threshold
  1140.         value, the pixel is subdivided into four
  1141.         subpixels and sampled again.  The corners of the
  1142.         subpixels are then compared against the threshold
  1143.         and if they are still too far apart the are
  1144.         subdivided once more.  The effective result of
  1145.         this is that in areas of constant or smoothly
  1146.         changing intensity only one ray per pixel is
  1147.         shot.  At edges or other sharp color transitions
  1148.         up to 25 rays per pixel may be averaged to
  1149.         determine the color of the pixel.  The result is
  1150.         fairly good antialiasing without too much undo
  1151.         overhead. 
  1152.  
  1153.     "threshold" is the threshold value used by the adaptive
  1154.  
  1155.                     20
  1156.  
  1157.  
  1158.  
  1159.         mode of antialiasing.  The default threshold is
  1160.         16.  Valid values are 0..255.  This parameter
  1161.         also affects the quick mode.  In general, lower
  1162.         values will produce better results but take more
  1163.         time. 
  1164.  
  1165.     "jitter" is a flag telling the system to add a little bit
  1166.         of randomness to the direction each ray is shot. 
  1167.         Combined with antialiasing this helps to break up
  1168.         the patterns sometimes caused by sampling an
  1169.         image on a regular grid.  Images with regular
  1170.         patterns such as checkerboards disappearing into
  1171.         the horizon will benefit most from jitter. 
  1172.  
  1173.     "aperture" is an optional parameter which allows the ray
  1174.         tracer to model a more realistic camera.  The
  1175.         default aperture is 0 which models a pinhole
  1176.         camera.  With an aperture greater than 0 objects
  1177.         at the focal length (see below) will appear in
  1178.         sharp focus while objects nearer or further from
  1179.         the viewpoint will be blurred.  The larger the
  1180.         aperture, the more exaggerated the blurring will
  1181.         be.  Using this option will greatly increase the
  1182.         amount of time needed to generate an image
  1183.         because Vivid uses distributed ray tracing to
  1184.         model the effects of a camera with a non-zero
  1185.         aperture.  This causes the number of rays
  1186.         necessary to calculate the color of a pixel to
  1187.         increase greatly.  The default is to shoot 8 rays
  1188.         instead of one ray whenever aperture is greater
  1189.         than zero.  This value can be controlled with the
  1190.         "samples" parameter below. 
  1191.  
  1192.     "focal_length" determines the distance from the camera to
  1193.         the focal plane where objects are rendered in
  1194.         focus.  This option is used in conjunction with
  1195.         the aperture option.  Objects which are a
  1196.         distance equal to the focal length away from the
  1197.         camera will be in sharp focus.  The default for
  1198.         the focal length is the distance between the
  1199.         "from" and "at" points which determine the
  1200.         viewpoint and the viewing direction. 
  1201.  
  1202.     "samples" controls the number of rays shot when a
  1203.         non-zero aperture is used.  The default is 8. 
  1204.  
  1205.     "no_shadows" causes all shadow calculations to be turned
  1206.         off.  The speed increase gained by turning
  1207.         shadows off is especially useful when doing test
  1208.         images of a new scene.  The can also be
  1209.         controlled using the command line switch -n. 
  1210.  
  1211.     "no_exp_trans" is a wonderfully intuitive name for a flag
  1212.  
  1213.                     21
  1214.  
  1215.  
  1216.  
  1217.         that turns off the exponential attenuation of the
  1218.         rays as they pass through transparent objects. 
  1219.         Got that? Let me try again.  Normally when Vivid
  1220.         shoots a ray through a transparent object (glass)
  1221.         the color of the ray is tinted by the color of
  1222.         the glass and is a function of the distance that
  1223.         the ray has to travel through the glass.  For
  1224.         example if you have two sheets of coke-bottle
  1225.         green glass where one is 1/4 inch thick and the
  1226.         other is 2 inches thick, light passing through
  1227.         the thicker one will be darker.  The relationship
  1228.         between the thickness and the amount of tinting
  1229.         is exponential.  This causes problems with single
  1230.         sided glass because when Vivid tries to compute
  1231.         the thickness of the glass the distance
  1232.         calculated is from the glass to whatever wall or
  1233.         floor the ray hits next.  Hence the windows will
  1234.         tend to be way dark.  When you set the
  1235.         no_exp_trans flag in the studio structure Vivid
  1236.         only uses the transparent color of the surface to
  1237.         calculate the tint and totally ignores the
  1238.         distance that the ray travels.  This tinting also
  1239.         affects shadow rays. 
  1240.  
  1241.     "caustics" is an experimental flag which turns on Vivid's
  1242.         faked caustics.  Caustics are those neat patterns
  1243.         of light that are produced as light passes
  1244.         through a transparent object.  I've been playing
  1245.         around with a couple of ways to get some of the
  1246.         effect without having to spend a few days per
  1247.         image doing the real thing.  The effect is pretty
  1248.         subtle but does seem to make some images look
  1249.         better.  Joe Bob says check it out. 
  1250.  
  1251.     "depth" lets you limit the maximum recursion level to
  1252.         which rays will be traced.  At a depth of 1 only
  1253.         eye rays are traced.  A depth of 2 will trace 1st
  1254.         level reflections and refractions.  The maximum
  1255.         value allowed is 20.  This is also the default
  1256.         value.  This can also be changed using the
  1257.         command line switch -d. 
  1258.  
  1259.     "bunching" allows you to control the branching factor of
  1260.         the tree created by the bounding boxes.  I'm not
  1261.         really sure what an optimal value is but the
  1262.         default value of 4 seems to work well for most
  1263.         cases.  At any rate, values less than two are
  1264.         guaranteed to cause grief.  Higher values will
  1265.         cause the bounding box tree to branch more at
  1266.         each level and therefore be shallower.  Lower
  1267.         values will do the opposite.  I find that
  1268.         experimenting with takes more time than I ever
  1269.         save so the only time I use it is when I am close
  1270.  
  1271.                     22
  1272.  
  1273.  
  1274.  
  1275.         to running out of memory.  Using a higher value
  1276.         like 8 or 12 will create fewer composite
  1277.         (bounding box) nodes in the tree and save soom
  1278.         memory.  Feel free not to ignore it without fear
  1279.         of missing out on something. 
  1280.  
  1281.  
  1282.  
  1283.  
  1284.  
  1285.  
  1286.  
  1287.  
  1288.  
  1289.  
  1290.  
  1291.  
  1292.  
  1293.  
  1294.  
  1295.  
  1296.  
  1297.  
  1298.  
  1299.  
  1300.  
  1301.  
  1302.  
  1303.  
  1304.  
  1305.  
  1306.  
  1307.  
  1308.  
  1309.  
  1310.  
  1311.  
  1312.  
  1313.  
  1314.  
  1315.  
  1316.  
  1317.  
  1318.  
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324.  
  1325.  
  1326.  
  1327.  
  1328.  
  1329.                     23
  1330.  
  1331.  
  1332.  
  1333.  
  1334.                      Lights
  1335.  
  1336.  
  1337.          Lights come in four flavors, point, directional, spherical
  1338.     and spot.  Just as the name implies a point light is a light
  1339.     source occupying a single point in space.  It has position,
  1340.     color, and attributes determining how much the intensity of the
  1341.     light falls off with distance.  A directional light acts like a
  1342.     point light source infinitely far away with no reduction in
  1343.     intensity over distance.  A spherical light source actually has a
  1344.     radius to it and can provide shadows with penumbra (soft edges). 
  1345.     This feature, however, adds a considerable amount to the time
  1346.     needed to render the image.  Spot lights produce a cone of light
  1347.     that falls off on the edges.  These are quite nice for
  1348.     highlighting areas of your model.  In most cases they also
  1349.     produce the least number of shadow rays making them quicker than
  1350.     just putting a point light inside a cone. 
  1351.  
  1352.          The definition for a point light source looks like this:
  1353.     
  1354.     light {
  1355.         type point
  1356.         falloff f            // defaults to 0
  1357.         position x y z
  1358.         color r g b
  1359.     }
  1360.     
  1361.  
  1362.          The falloff parameter determines how the intensity of the
  1363.     light is reduced over distance(dist).  In the real world the
  1364.     light intensity falls off as 1/(dist*dist) (f=2).  Vivid also
  1365.     allows the light to fall off as 1/dist (f=1) and not to fall off
  1366.     at all (f=0).  Why would you want to use anything except f=2?
  1367.     Simplicity is one reason.  With f=0 you can set the light's color
  1368.     to 1 1 1 and know that whatever objects the light falls on will
  1369.     be illuminated fully regardless of the distance of the light from
  1370.     the object.  With f=2 you must take into account this distance. 
  1371.     If the object you wish to be illuminated is 3 units away from the
  1372.     light then in order to get the same amount of illumination that
  1373.     f=0 provides you must set the color to 9 9 9 ie 3^2.  For f=1 the
  1374.     color would have to be 3 3 3.  In the real world much of the
  1375.     light around us does not come directly from the light source.  It
  1376.     often bounces off of other objects on its way to the object we
  1377.     are interested in.  Since Vivid, like most ray tracers, does not
  1378.     model this interobject diffuse reflection we can achieve much the
  1379.     same effect by have the light intensity fall off linearly with
  1380.     distance, ie f=1.  The default value is f=0. 
  1381.  
  1382.          The definition for a directional light source looks like:
  1383.     
  1384.     light {
  1385.         type directional
  1386.  
  1387.                     24
  1388.  
  1389.  
  1390.  
  1391.         color r g b
  1392.         direction dx dy dz
  1393.     }
  1394.     
  1395.     or the direction can be replaced by a from and at pair:
  1396.     
  1397.     light {
  1398.         type directional
  1399.         color r g b
  1400.         from x y z
  1401.         at x y z
  1402.     }
  1403.     
  1404.     
  1405.  
  1406.          The direction vector points along the direction the light is
  1407.     travelling.  Since the light is assumed to be at infinity, there
  1408.     is no falloff parameter.  If you are having difficulty
  1409.     understanding how the direction parameter works is is sometimes
  1410.     useful to note that direction x y z is the same as center 0 0 0
  1411.     at x y z. 
  1412.  
  1413.          The definition for a spherical light source looks like:
  1414.     
  1415.     light {
  1416.         type spherical
  1417.         position x y z
  1418.         radius r
  1419.         color r g b
  1420.         falloff f
  1421.         samples n
  1422.     }
  1423.     
  1424.  
  1425.          Spherical lights differ from point lights in that the
  1426.     shadows they cast have penumbra.  Normally when a ray hits a
  1427.     surface a shadow ray is shot toward each light.  If the shadow
  1428.     ray hits any surface on the way to the light then that light is
  1429.     blocked and the surface is in the shadow of the blocking object. 
  1430.     With spherical light sources multiple shadow rays are shot.  Each
  1431.     one is shot to a random point within the radius of the light.  If
  1432.     the light is half blocked by an object, approximately half the
  1433.     shadow rays will be blocked and half will pass through to the
  1434.     light.  The ratio of blocked to not-blocked shadow rays is then
  1435.     used to determine how strong the shadow is.  As you might expect,
  1436.     the extra shadow rays will add a lot of extra time to the
  1437.     rendering.  Some references refer to these light sources as
  1438.     extended light sources.  The number of shadow rays shot each time
  1439.     is controlled by the samples parameter.  The default value for
  1440.     this is 16. 
  1441.  
  1442.          The definition for a spot light source looks like:
  1443.     
  1444.  
  1445.                     25
  1446.  
  1447.  
  1448.  
  1449.     light {
  1450.         type spot
  1451.         position x y z
  1452.         direction dx dy dz
  1453.         min_angle angle1
  1454.         max_angle angle2
  1455.         color r g b
  1456.         falloff f
  1457.     }
  1458.     
  1459.  
  1460.          Like the directional light, the direction parameter may be
  1461.     replaced with the at x y z to specify where the light is shining. 
  1462.     Min_angle and max_angle define the shape of the cone of light
  1463.     produced by the spot light.  Everything within the min_angle
  1464.     angle of the axis of the light will be fully illuminated.  From
  1465.     there the light intensity will fall off until max_angle is
  1466.     reached.  For example if you want a cone of light 30 degrees wide
  1467.     with sharp edges you would define min_angle and max_angle to be
  1468.     30.  To get the same size light but one that fades out at the
  1469.     edges you would define max_angle to be 30 and min_angle to be 0. 
  1470.  
  1471.          Each light source can also have a couple of other
  1472.     parameters.  They are no_shadows and no_spec.  As you've probably
  1473.     guessed, these allow you to turn off shadows and specular
  1474.     highlights for each light.  Used together with a directional
  1475.     light source of low intensity (.2 .2 .2) this is often a nice
  1476.     alternative to global ambient light.  Global ambient light tends
  1477.     to make objects appear flat whereas this technique will provide
  1478.     subtle shading without the shadows and spots of your "real" light
  1479.     sources. 
  1480.  
  1481.          One thing to note is that even if a light is within the
  1482.     viewing scene it will not appear as an object.  If you want you
  1483.     lights to be visible you can wrap a transparent shell around them
  1484.     using a sphere.  Example:
  1485.     
  1486.     //      Define a point light at 2 3 4 that shows up in the scene
  1487.     //      as a light with radius 1.
  1488.     
  1489.     light {
  1490.         center 2 3 4
  1491.         type point
  1492.         color white
  1493.     }
  1494.     
  1495.     //      glass shell
  1496.     
  1497.     surface {
  1498.         ambient white        // same color as the light
  1499.         transparent white    // totally transparent
  1500.     }
  1501.     sphere {
  1502.  
  1503.                     26
  1504.  
  1505.  
  1506.  
  1507.         center 2 3 4
  1508.         radius 1
  1509.     }
  1510.     
  1511.     For details on spheres and surfaces skip ahead. 
  1512.  
  1513.  
  1514.  
  1515.  
  1516.  
  1517.  
  1518.  
  1519.  
  1520.  
  1521.  
  1522.  
  1523.  
  1524.  
  1525.  
  1526.  
  1527.  
  1528.  
  1529.  
  1530.  
  1531.  
  1532.  
  1533.  
  1534.  
  1535.  
  1536.  
  1537.  
  1538.  
  1539.  
  1540.  
  1541.  
  1542.  
  1543.  
  1544.  
  1545.  
  1546.  
  1547.  
  1548.  
  1549.  
  1550.  
  1551.  
  1552.  
  1553.  
  1554.  
  1555.  
  1556.  
  1557.  
  1558.  
  1559.  
  1560.  
  1561.                     27
  1562.  
  1563.  
  1564.  
  1565.  
  1566.                     Surfaces
  1567.  
  1568.  
  1569.          Surface structures allow you to define the surface
  1570.     characteristics of the objects you are rendering such as color,
  1571.     reflectivity and texture.  When a surface is defined in the input
  1572.     file, it is applied to all the primitives following it until a
  1573.     new surface is defined.  This allows multiple objects to be
  1574.     entered without having to repeat the surface characteristics.  A
  1575.     simple surface structure looks like this:
  1576.     
  1577.     surface {
  1578.         diffuse r g b        // defaults to 0 0 0 (black)
  1579.         ambient r g b        // defaults to 0 0 0
  1580.         specular r g b       // defaults to 0 0 0
  1581.         shine pow            // defaults to 0
  1582.         transparent r g b    // defaults to 0 0 0
  1583.         ior num              // defaults to 1.0
  1584.         fuzz magnitude       // defaults to 0.0
  1585.         no_antialias         // turn off antialiasing
  1586.     }
  1587.     
  1588.  
  1589.          All of these components of the surface are figured in when
  1590.     the ray tracer determines the color of an object in the scene. 
  1591.     The diffuse color is the actual color of the object as seen when
  1592.     illuminated by a full white light.  A value of 0 0 0 signifies a
  1593.     black object while a value of 1 1 1 indicates white.  The
  1594.     brightness of this component depends on the amount of light
  1595.     falling on the surface at that point.  The ambient term is
  1596.     sometimes also referred to as the self-luminous component.  This
  1597.     is the color the object will appear in a totally dark scene.  The
  1598.     specular component specifies the reflectivity of the surface.  A
  1599.     value of 1 1 1 will produce a mirror-like reflection.  The shine
  1600.     value determines how large the specular spot will appear on a
  1601.     surface.  Low values, 1..10, will produce large, soft-edged
  1602.     specular highlights while high values, 1000 or more, will produce
  1603.     a small, sharp spot.  Traditionally the brightness and color of
  1604.     the spot is in direct proportion to the specular component.  The
  1605.     problem is that sometimes it would be nice to have a blue object
  1606.     with specular highlights without having the extra overhead of
  1607.     tracing reflected rays.  Therefore Vivid allows a second form for
  1608.     defining specular spots:
  1609.     
  1610.         shine pow r g b
  1611.     
  1612.  
  1613.          In this case the color given will be used instead of the
  1614.     specular component of the surface.  The transparent component
  1615.     allows you to define how transparent the surface is.  A value of
  1616.     1 1 1 will appear glass-like because it allows all colors to pass
  1617.     through while a value of 1 0 0 will produce a surface like red
  1618.  
  1619.                     28
  1620.  
  1621.  
  1622.  
  1623.     glass since it only allows red light to pass through.  A surface
  1624.     with a transparent component of .9 .9 .9 will appear partially
  1625.     transparent with the amount of light passed through based on the
  1626.     thickness of the object the light is passing through.  The index
  1627.     of refraction, ior, determines how much the ray is bent as it
  1628.     passes into the transparent surface.  In reality this is related
  1629.     to the relative density of the surface.  To simulate glass values
  1630.     of about 1.1 to 1.3 seem to work best.  The ior of diamond is
  1631.     2.6.  Fuzz is a way of adding random noise to the surface normal
  1632.     of the object when its color is determined.  Since the diffuse
  1633.     color of the object is affected by the angle the light hits the
  1634.     surface this randomization can produce a sort of coarse texuture
  1635.     to an object.  Applied to mirrored or transparent surfaces this
  1636.     produces an affect much like frosted glass.  Generally, small
  1637.     values of fuzz, .01 to .3, seem to work best. 
  1638.  
  1639.          The no_antialias flag tells the adaptive antialiasing to
  1640.     effectively turn off for that surface.  In general this is not
  1641.     something that you want to do except in a few special cases.  The
  1642.     original reason for this parameter was that fuzzy surfaces can
  1643.     cause the adaptive antialias option to shoot lots of rays and
  1644.     slow down the image generation considerably.  By adding the
  1645.     no_antialias flag to the surface definition you still get the
  1646.     benefits of the adaptive antialiasing along the edges of the
  1647.     objects but you avoid the slowdown that can be caused by any
  1648.     large, fuzzy surfaces.  Note, however, that this will change the
  1649.     look of the surface.  Try cutting the amount of fuzz in half when
  1650.     using this option to preserve the amount of color variation in
  1651.     the surface. 
  1652.  
  1653.          As an aid to those of us that can't type, some keywords may
  1654.     be abbreviated: surf, diff, amb, spec and trans.  I trust that
  1655.     you'll be able to figure out what goes with what. 
  1656.  
  1657.          Some examples are probably in order. 
  1658.     
  1659.     //      simple red surface
  1660.     surface {
  1661.         diff 1 0 0
  1662.     }
  1663.     
  1664.     //      self-luminous blue
  1665.     surface {
  1666.         ambient 0 0 1
  1667.     }
  1668.     
  1669.     //      mirror with specular highlights
  1670.     surface {
  1671.         spec 1 1 1
  1672.         shine 100
  1673.     }
  1674.     
  1675.     //      glass with some reflection
  1676.  
  1677.                     29
  1678.  
  1679.  
  1680.  
  1681.     surface {
  1682.         spec .3 .3 .3
  1683.         shine 30
  1684.         trans .7 .7 .7
  1685.         ior 1.2
  1686.     }
  1687.     
  1688.  
  1689.          In general, the rule of thumb is that amb+diff+spec+trans
  1690.     should be less than or equal to 1 1 1.  Of course since we are
  1691.     defining our own universe anything is possible. 
  1692.  
  1693.  
  1694.  
  1695.  
  1696.  
  1697.  
  1698.  
  1699.  
  1700.  
  1701.  
  1702.  
  1703.  
  1704.  
  1705.  
  1706.  
  1707.  
  1708.  
  1709.  
  1710.  
  1711.  
  1712.  
  1713.  
  1714.  
  1715.  
  1716.  
  1717.  
  1718.  
  1719.  
  1720.  
  1721.  
  1722.  
  1723.  
  1724.  
  1725.  
  1726.  
  1727.  
  1728.  
  1729.  
  1730.  
  1731.  
  1732.  
  1733.  
  1734.  
  1735.                     30
  1736.  
  1737.  
  1738.  
  1739.  
  1740.                   Bump Mapping
  1741.  
  1742.          Bump mapping is a means of giving a surface some texture
  1743.     which enhances the realism of the surface by adding ripples or
  1744.     bumps to the surface.  The surface isn't actually distorted but
  1745.     its normal is.  This allows a simple surface to appear very
  1746.     complicated.  Bump definitions are included inside of the simple
  1747.     surface definitions, ie:
  1748.     
  1749.     surface {
  1750.         diffuse red
  1751.         bump {
  1752.             ...
  1753.         }
  1754.     }
  1755.     
  1756.     A sample wave bump map looks like this:
  1757.     
  1758.     bump {
  1759.         wave {
  1760.             center 1 2 3
  1761.             wavelength 2.0
  1762.             amplitude 0.2
  1763.             damping 0.9          // defaults to 1.0
  1764.             phase 0.0            // defaults to 0.0
  1765.         }
  1766.     }
  1767.     
  1768.  
  1769.          Center defines the source of the wave.  Wavelength defines
  1770.     the crest to crest distance of the wave.  Amplitude defines the
  1771.     maximum amount that the surface normal is bumped.  Values under 1
  1772.     are definitely best.  The damping parameter defines how much the
  1773.     amplitude falls with distance.  In the example given the
  1774.     amplitude will decrease by 10% for each wavelength of distance
  1775.     from the source.  The phase is a number between 0 and 1 which
  1776.     defines a starting offset for the phase of the wave.  This can be
  1777.     used in animations to create a wave which appears to move
  1778.     realistically by incrementing the phase by a small amount for
  1779.     each frame.  More than one wave may be defined within the bump
  1780.     structure.  By defining three or four wave sources at various
  1781.     locations with differing wavelengths and amplitudes a very
  1782.     realistic rippled surface can be created. 
  1783.  
  1784.  
  1785.  
  1786.  
  1787.  
  1788.  
  1789.  
  1790.  
  1791.  
  1792.  
  1793.                     31
  1794.  
  1795.  
  1796.  
  1797.  
  1798.          Turbulence can also be used to perturb the normal of a
  1799.     surface.  The definition of turbulence looks like this:
  1800.     
  1801.     bump {
  1802.         turbulence {
  1803.             scale 1 1 1
  1804.             offset 0 0 0
  1805.             amplitude .5
  1806.             terms 4
  1807.         }
  1808.     }
  1809.     
  1810.  
  1811.          The turbulence function takes the location of the ray
  1812.     intersection and returns a random number in the range +-
  1813.     amplitude.  The scale and offset factors are applied to the xyz
  1814.     location before the turbulence function is called.  The terms
  1815.     parameter allows you to build a fractal-like surface.  When
  1816.     terms>1 the turbulence function is summed multiple times.  Each
  1817.     successive term in the sum has its scaling doubled and the
  1818.     amplitude halved.  This produces the varying levels of
  1819.     self-similarity associated with fractals.  The sample file
  1820.     vivid1.v uses this feature and a non-symmetric scaling to produce
  1821.     the "spun-chrome" look on the large sphere.  Turbulence and wave
  1822.     definitions may be included with each other inside a bump
  1823.     definition. 
  1824.  
  1825.  
  1826.  
  1827.  
  1828.  
  1829.  
  1830.  
  1831.  
  1832.  
  1833.  
  1834.  
  1835.  
  1836.  
  1837.  
  1838.  
  1839.  
  1840.  
  1841.  
  1842.  
  1843.  
  1844.  
  1845.  
  1846.  
  1847.  
  1848.  
  1849.  
  1850.  
  1851.                     32
  1852.  
  1853.  
  1854.  
  1855.  
  1856.                 Textured Surfaces
  1857.  
  1858.  
  1859.          Vivid also allows the use of solid texturing to enhance the
  1860.     realism of the surfaces rendered.  Textured surfaces are really
  1861.     just two surfaces with some definition of which appears where on
  1862.     the object and how the two surfaces are blended together.  The
  1863.     surfaces can be "layered" in one of three patterns checker,
  1864.     spherical or noise.  The checker pattern produces a 3-d checker. 
  1865.     The size of the blocks is controlled by the scale factor.  If one
  1866.     of the scale parameters is 0 then the pattern is assumed not to
  1867.     change along that axis.  An example would be a simple
  1868.     checkerboard pattern with checkers 2 units on a side colored
  1869.     black and white.  This pattern is defined to extend infinitely
  1870.     along the z axis. 
  1871.     
  1872.     surface {
  1873.         texture {
  1874.             pattern checker
  1875.             scale 2 2 0
  1876.             offset 0 0 0                 // default
  1877.             fuzz 0                       // default
  1878.             blend 0                      // default
  1879.             surface { diff black }
  1880.             surface { diff white }
  1881.         }
  1882.     }
  1883.     
  1884.  
  1885.          A scale of 2 0 0 would create a pattern which changes every
  1886.     2 units in the x direction but is continuous in the y and z
  1887.     directions.  This is equivalent to 2-unit thick slabs of material
  1888.     stacked along the x axis.  The spherical pattern produces
  1889.     concentric layers of alternating surfaces.  When one of the scale
  1890.     parameters is 0 concentric cylinders are formed with the axis of
  1891.     the cylinders along the zero'ed axis.  This is useful for wood
  1892.     textures.  The spherical pattern also requires 2 radius
  1893.     definitions for the layers.  The first radius is used for the
  1894.     first surface, etc. 
  1895.     
  1896.     surface {
  1897.         texture {
  1898.             pattern spherical
  1899.             scale 2 2 0
  1900.             radius 1
  1901.             radius 2
  1902.             surface { diff black }
  1903.             surface { diff white }
  1904.         }
  1905.     }
  1906.     
  1907.  
  1908.  
  1909.                     33
  1910.  
  1911.  
  1912.  
  1913.  
  1914.          The noise pattern uses the output of the noise function
  1915.     directly to pick between the two surfaces.  This is useful for
  1916.     producing textures like granite.  By using unequal scaling values
  1917.     in the x y and z directions you can get a streaked looking
  1918.     surface.  I've also used this using tan and brown surfaces to
  1919.     produce a fine wood-grain look. 
  1920.     
  1921.     surface {
  1922.         texture {
  1923.             pattern noise
  1924.             terms 4
  1925.             scale x y z
  1926.             surface { diff white }
  1927.             surface { diff black }
  1928.         }
  1929.     }
  1930.     
  1931.  
  1932.          The fuzz and blend parameters may be used to soften the
  1933.     edges between the two surfaces.  Their values range from 0 to 1. 
  1934.     The blend parameter produces a smooth transition between the
  1935.     surfaces.  The value of the blend parameter determines the width
  1936.     of this transition area.  The fuzz parameter adds noise to the
  1937.     point being checked in proportion to its value.  This produces a
  1938.     coarse, speckled transition between the surfaces. 
  1939.  
  1940.          The turbulence function mention in the bump map section may
  1941.     also be applied to textured surfaces.  By varying the parameters
  1942.     the effect can be made to range from a slight perturbation of the
  1943.     pattern, to a marble look, to excessive turbulence.  A simple
  1944.     example is presented below. 
  1945.  
  1946.          Due to the way Vivid's parser works if you want to bump map
  1947.     a surface which is also textured the bump definition must appear
  1948.     in the surface structure before the texture definition.  Also
  1949.     notice that the surfaces defined in a texture definition need not
  1950.     be simple surfaces.  They may also be textured.  The following is
  1951.     a definition for a checkerboard surface with checks 10 units on a
  1952.     side.  Half the checks are black while the other half have a
  1953.     red/white marble finish. 
  1954.     
  1955.     surface {
  1956.         texture {
  1957.             pattern checker
  1958.             scale 10 10 0
  1959.             surface { diff black }
  1960.             surface {
  1961.                 texture {
  1962.                     pattern checker
  1963.                     scale 1 0 0
  1964.                     blend 0.7
  1965.                     turbulence {
  1966.  
  1967.                     34
  1968.  
  1969.  
  1970.  
  1971.                         amplitude 3
  1972.                         terms 4
  1973.                     }
  1974.                     surface { diff white }
  1975.                     surface { diff red }
  1976.                 }
  1977.             }
  1978.         }
  1979.     }
  1980.     
  1981.  
  1982.  
  1983.  
  1984.  
  1985.  
  1986.  
  1987.  
  1988.  
  1989.  
  1990.  
  1991.  
  1992.  
  1993.  
  1994.  
  1995.  
  1996.  
  1997.  
  1998.  
  1999.  
  2000.  
  2001.  
  2002.  
  2003.  
  2004.  
  2005.  
  2006.  
  2007.  
  2008.  
  2009.  
  2010.  
  2011.  
  2012.  
  2013.  
  2014.  
  2015.  
  2016.  
  2017.  
  2018.  
  2019.  
  2020.  
  2021.  
  2022.  
  2023.  
  2024.  
  2025.                     35
  2026.  
  2027.  
  2028.  
  2029.  
  2030.          Vivid also allows a Mandelbrot pattern as demonstrated in
  2031.     the sample input file vivid1.v.  The Mandelbrot pattern was put
  2032.     into Vivid as a joke one evening.  Currently the format for
  2033.     specifying it is terrible.  The first two parameters of the scale
  2034.     value determine the x y scaling of the set while the 3rd
  2035.     parameter determines the maximum number of iterations.  The
  2036.     result of the iteration calculation is then scaled by the max
  2037.     number of iterations to determine the relative percentages of the
  2038.     surface parameters for that point. 
  2039.  
  2040.          OK, the way it works is like this.  The actual point of
  2041.     intersection, x y z, is tranlated using the scale and offset
  2042.     values before being put into the Mandelbrot calculation. 
  2043.  
  2044.          new_x = x * scale_x + offset
  2045.  
  2046.          Like I said, this is about a backwards as I could make it
  2047.     and still have it work.  Since the point is multiplied by the
  2048.     scale rather than divided the pattern gets bigger as the scale
  2049.     value gets smaller.  Normally the Mandelbrot set extends from -2
  2050.     to +1 along the x axis (more or less).  If you want to get it to
  2051.     fit from -20 to +10 you would have to scale it by 0.1 in the x
  2052.     and y axes.  Stupid? Yes.  Now, since the offset is added on
  2053.     after the multiplication that makes it work in the Mandelbrot
  2054.     coordinate system rather than the world coordinate system. 
  2055.     Continuing the example above, if you wanted to move the center of
  2056.     the set to world coordinates 300, 100 you would have to give an
  2057.     offset of 30 10. 
  2058.  
  2059.          Using macros I think you can alleviate most of this garbage. 
  2060.         #define ITERATION_LIMIT         (64)
  2061.         #define SCALE                   (10)
  2062.         #define X_OFFSET                (300)
  2063.         #define Y_OFFSET                (100)
  2064.     
  2065.         surf {
  2066.             texture {
  2067.                 pattern mandelbrot
  2068.                 scale (1/SCALE) (1/SCALE) ITERATION_LIMIT
  2069.                 offset (X_OFFSET/SCALE) (Y_OFFSET/SCALE) 0
  2070.               //  etc...
  2071.     
  2072.                 }
  2073.     
  2074.  
  2075.          Now all you have to do is change the defines and things will
  2076.     work much more like you expect. 
  2077.  
  2078.          Once I figure out a reasonable way of doing this Mandelbrot
  2079.     and Julia sets will become a real part of Vivid.  (Yeah, I know I
  2080.     said that last time but it's still true.)
  2081.  
  2082.  
  2083.                     36
  2084.  
  2085.  
  2086.  
  2087.  
  2088.                      Sphere
  2089.  
  2090.          The sphere is the simplest of the primitives supported by
  2091.     Vivid and generally the fastest to perform an intersection test
  2092.     with.  The format for a sphere is:
  2093.     
  2094.     sphere {
  2095.         center x y z
  2096.         radius r
  2097.     }
  2098.     
  2099.     where x y z is the location in space for the center of the sphere
  2100.     and r is the sphere's radius.  As an example here is the
  2101.     definition for two glass spheres, one which is hollow and one
  2102.     which is solid. 
  2103.     
  2104.     //      glass surface
  2105.     
  2106.     surface { trans 1 1 1 shine 200 1 1 1 ior 1.2 }
  2107.     
  2108.     //      solid globe
  2109.     
  2110.     sphere { center 1 0 0 radius .9 }
  2111.     
  2112.     //      hollow globe
  2113.     
  2114.     sphere { center -1 0 0 radius .9 }      // outer surface
  2115.     sphere { center -1 0 0 radius .8 }     // inner surface
  2116.     
  2117.  
  2118.          Just for laughs vivid also includes a fuzzy spheres option. 
  2119.     These spheres appear fuzzy because they have no fixed radius.  To
  2120.     define a fuzzy sphere define a normal sphere and add a fuzz
  2121.     parameter.  This defines how much larger the radius will randomly
  2122.     be.  Each time the ray tracer performs an intersection test with
  2123.     the fuzzy sphere, the radius to test against is randomly chosen
  2124.     to lie between the radius and radius+fuzz. 
  2125.     
  2126.     //      fuzzy sphere with radius between 0.5 and 2
  2127.     sphere {
  2128.         center 0 1 2
  2129.         radius .5
  2130.         fuzz 1.5
  2131.     }
  2132.     
  2133.     
  2134.  
  2135.  
  2136.  
  2137.  
  2138.  
  2139.  
  2140.  
  2141.                     37
  2142.  
  2143.  
  2144.  
  2145.  
  2146.                       Ring
  2147.  
  2148.          The ring primitive may also be described as a washer or
  2149.     disk.  The definition for a ring consists of a location, a
  2150.     surface normal, and a minimum and maximum radius.  The minimum
  2151.     radius may be zero producing a disk without a center hole. 
  2152.     Because the intersection for the ring is faster than for a
  2153.     polygon the ring is a good choice for use as a ground plane
  2154.     underneath the objects you are ray tracing.  The format for the
  2155.     ring definition is:
  2156.     
  2157.     ring {
  2158.         center x y z
  2159.         normal a b c
  2160.         min_radius r0
  2161.         max_radius r1
  2162.     }
  2163.     
  2164.  
  2165.          The surface normal a b c does not have to be normalized.  If
  2166.     you just want a disk without a center hole the min/max radius
  2167.     definitions may be replaced with a single radius definition as
  2168.     follows. 
  2169.     
  2170.     ring {
  2171.         center x y z
  2172.         normal a b c
  2173.         radius r
  2174.     }
  2175.     
  2176.     
  2177.  
  2178.          Whoa, just got a clue that not everyone knows what a surface
  2179.     normal is.  A surface normal is a vector that is perpendicular to
  2180.     a surface, ie one that points straight out from the surface.  For
  2181.     example, the surface normal for the floor in you room would be a
  2182.     vector pointing straight up into the air.  The surface normal of
  2183.     your monitor is the vector pointing straight out between you
  2184.     eyes.  Simple enough? Ok, now a normalized vector is one which
  2185.     has been scaled to have its length equal exactly 1.  This is
  2186.     usually done by calculating the length of the vector then
  2187.     dividing each of the vector's components by the length.  Vectors
  2188.     of length 0 cause no end of problems. 
  2189.  
  2190.  
  2191.  
  2192.  
  2193.  
  2194.  
  2195.  
  2196.  
  2197.  
  2198.  
  2199.                     38
  2200.  
  2201.  
  2202.  
  2203.  
  2204.                      Polygon
  2205.  
  2206.          Polygons may have any number of vertices (well, a minimum of
  2207.     three is required).  The vertices must all lie within the same
  2208.     plane otherwise the results will be strange.  The order of the
  2209.     vertices may be either clockwise or counter clockwise. 
  2210.     
  2211.     polygon {
  2212.         points 4
  2213.         vertex  1  1 0
  2214.         vertex  1 -1 0
  2215.         vertex -1 -1 0
  2216.         vertex -1  1 0
  2217.     }
  2218.     
  2219.  
  2220.  
  2221.          This will produce a square polygon 2 units on a side
  2222.     centered at the origin with a surface normal equal to 0 0 1. 
  2223.  
  2224.  
  2225.  
  2226.  
  2227.  
  2228.  
  2229.  
  2230.  
  2231.  
  2232.  
  2233.  
  2234.  
  2235.  
  2236.  
  2237.  
  2238.  
  2239.  
  2240.  
  2241.  
  2242.  
  2243.  
  2244.  
  2245.  
  2246.  
  2247.  
  2248.  
  2249.  
  2250.  
  2251.  
  2252.  
  2253.  
  2254.  
  2255.  
  2256.  
  2257.                     39
  2258.  
  2259.  
  2260.  
  2261.  
  2262.                 Triangular Patch
  2263.  
  2264.          The triangular patch is useful for building objects with
  2265.     complex shapes that you want to appear smooth.  The patch is
  2266.     defined by three vertices and explicit surface normals for each
  2267.     vertex.  In general, manually entering in patches will probably
  2268.     be too tedious to be of much use but when using computer
  2269.     generated input files the results will be worth the extra
  2270.     programming effort. 
  2271.     
  2272.     patch {
  2273.         vertex 1 0 0 normal .1 0 1
  2274.         vertex 0 1 1 normal 0 .1 1
  2275.         vertex 0 0 .5 normal -.1 -.1 1
  2276.     }
  2277.     
  2278.  
  2279.  
  2280.  
  2281.  
  2282.  
  2283.  
  2284.  
  2285.  
  2286.  
  2287.  
  2288.  
  2289.  
  2290.  
  2291.  
  2292.  
  2293.  
  2294.  
  2295.  
  2296.  
  2297.  
  2298.  
  2299.  
  2300.  
  2301.  
  2302.  
  2303.  
  2304.  
  2305.  
  2306.  
  2307.  
  2308.  
  2309.  
  2310.  
  2311.  
  2312.  
  2313.  
  2314.  
  2315.                     40
  2316.  
  2317.  
  2318.  
  2319.  
  2320.                       Cone
  2321.  
  2322.          The cones implemented by Vivid are actually truncated cones. 
  2323.     They have a radius both at their base and at their apex.  When
  2324.     these radii are equal the cone does a fair imitation of a
  2325.     cylinder.  To get a pointed cone enter 0 for one of the radii. 
  2326.     
  2327.     cone {
  2328.         base 1 1 1 base_radius 4
  2329.         apex 0 0 5 apex_radius 1
  2330.     }
  2331.     
  2332.  
  2333.          Rings are useful for putting caps on the ends of cones. 
  2334.     Even for a cone at an odd angle the position and normal of the
  2335.     ring can be easily calculated.  To cap the apex end of the cone
  2336.     the ring's center is equal to the apex, the ring's radius is
  2337.     equal to the apex_radius and the ring's normal is equal to
  2338.     apex-base.  Using the example above the definition for a ring to
  2339.     cap the apex end of the cone would look like this:
  2340.     
  2341.     ring {
  2342.         center 0 0 5
  2343.         radius 1
  2344.         normal -1 -1 4
  2345.     }
  2346.     
  2347.  
  2348.  
  2349.  
  2350.  
  2351.  
  2352.  
  2353.  
  2354.  
  2355.  
  2356.  
  2357.  
  2358.  
  2359.  
  2360.  
  2361.  
  2362.  
  2363.  
  2364.  
  2365.  
  2366.  
  2367.  
  2368.  
  2369.  
  2370.  
  2371.  
  2372.  
  2373.                     41
  2374.  
  2375.  
  2376.  
  2377.  
  2378.                  Transformations
  2379.  
  2380.  
  2381.          Vivid's transformation commands allow you to move and scale
  2382.     objects.  Transformation commands apply to all the primitives
  2383.     following them until they are "popped" from the transformation
  2384.     stack.  The format for a transformation command is:
  2385.     
  2386.     transform {
  2387.         scale           s
  2388.         rotate          x y z
  2389.         translate       dx dy dz
  2390.     }
  2391.     
  2392.  
  2393.          Scale changes the size of the objects.  Scale may also be
  2394.     defined as a vector to create objects that are scaled differently
  2395.     in each axis.  Unfortunately this doesn't work with all
  2396.     primitives, only polygons and patches can be scaled
  2397.     non-uniformally.  The rotate command rotates the object the given
  2398.     number of degrees around each axis.  The translate command moves
  2399.     the object.  Any of these may be left out or used more than once. 
  2400.     They can also be used in any order and will be applied to the
  2401.     objects in the order that they are given.  It is very important
  2402.     that you get the order correct.  An object that is rotated 90
  2403.     degrees around the Z axis and translated 10 units along the X
  2404.     axis will end up at 10 0 0 with a 90 degree twist whereas if the
  2405.     operations are applied in the other order the object will end up
  2406.     at 0 10 0.  Sometimes it helps to play around with real objects a
  2407.     bit and work through some of the transformations first.  Remember
  2408.     that all rotations are done around the axes, not necessarily
  2409.     around the center of the object.  This should also be kept in
  2410.     mind when building new objects.  Put 0 0 0 at the objects
  2411.     "natural" center of rotation.  This will help greatly when
  2412.     building scenes with the objects.  For example, the natural
  2413.     "center" for a car model would be at ground level in the center
  2414.     of the car.  This allows the car to fairly easily be placed in
  2415.     the scene where you want it. 
  2416.  
  2417.          To remove a transformation from the transform stack use the
  2418.     "transform_pop" command.  Sometimes you will want to nest
  2419.     transform commands.  This is useful for creating multi-part
  2420.     objects that move relative to each other but also need to move as
  2421.     a whole unit.  For example, say you want to create a tank model
  2422.     with a turret that you can rotate.  Assume that the body of your
  2423.     tank model is in the file tank.vo and the turret is in turret.vo. 
  2424.     To place the tank in your scene, your input file would look like
  2425.     this:
  2426.     
  2427.     #define TURRET_ANGLE    (30)    // rotation for turret
  2428.     
  2429.     transform { translate x y z }   // move whole tank
  2430.  
  2431.                     42
  2432.  
  2433.  
  2434.  
  2435.     #include tank.vo                // include body geometry
  2436.     transform { rotate 0 0 TURRET_ANGLE }
  2437.     #include turret.vo              // include turret geometry
  2438.     
  2439.     transform_pop           // clean up transform stack
  2440.     transform_pop
  2441.     
  2442.  
  2443.          Using this technique complicated models can be built and
  2444.     positioned with relative ease.  There is currently one major
  2445.     drawback to using transformations, surface textures don't move
  2446.     with the object.  This isn't too big a deal for single frame
  2447.     images but will make animating textured objects look very poor. 
  2448.     Yes, I'm working on it. 
  2449.  
  2450.  
  2451.  
  2452.  
  2453.  
  2454.  
  2455.  
  2456.  
  2457.  
  2458.  
  2459.  
  2460.  
  2461.  
  2462.  
  2463.  
  2464.  
  2465.  
  2466.  
  2467.  
  2468.  
  2469.  
  2470.  
  2471.  
  2472.  
  2473.  
  2474.  
  2475.  
  2476.  
  2477.  
  2478.  
  2479.  
  2480.  
  2481.  
  2482.  
  2483.  
  2484.  
  2485.  
  2486.  
  2487.  
  2488.  
  2489.                     43
  2490.  
  2491.  
  2492.  
  2493.  
  2494.                     Clipping
  2495.  
  2496.  
  2497.          Primitives can also be "clipped" to produce more complicated
  2498.     shapes.  Basically the way a clip works is that a primitive is
  2499.     defined with a clipping surface which cuts off part of that
  2500.     primitive.  For example a sphere can be clipped against a plane
  2501.     to produce a hemisphere or a cone can be used to clip a hole
  2502.     through another cone.  There are three types of clipping surface:
  2503.     planes, spheres and cones.  Clips are defined within a
  2504.     primitive's definiton.  You may have more than one clip per
  2505.     primitive.  Clips also transform along with their primitives. 
  2506.  
  2507.          A clipping plane is defined by a point and a normal. 
  2508.         clip {
  2509.             center x y z
  2510.             normal x y z
  2511.         }
  2512.     
  2513.  
  2514.          The part of the primitive on the normal side of the plane
  2515.     will be kept while the part on the other side will disappear into
  2516.     the Ronald Reagan Memorial Library.  (You may think I'm lying but
  2517.     you'll never really _know_ until you go check.) For example, if
  2518.     you want to get a hemipshere of radius 1 centered at the origin
  2519.     if would look like:
  2520.         sphere {
  2521.             center 0 0 0 radius 1
  2522.             clip {
  2523.                 center 0 0 0 normal 0 0 1
  2524.             }
  2525.         }
  2526.     
  2527.  
  2528.          Note that the clip's normal is pointing upward.  This will
  2529.     give you the top half of the sphere.  If you change the normal to
  2530.     0 0 -1 you will get the bottom half. 
  2531.  
  2532.          Clipping spheres are defined as:
  2533.         clip {
  2534.             center x y z
  2535.             radius r
  2536.             inside or outside
  2537.         }
  2538.     
  2539.  
  2540.          With a clipping sphere you can choose to either keep the
  2541.     part of the primitive inside of the sphere or the part of the
  2542.     primitive outside of the sphere.  You may have already guessed
  2543.     this but that's why the inside and outside keywords are there. 
  2544.  
  2545.          Clipping cones look like:
  2546.  
  2547.                     44
  2548.  
  2549.  
  2550.  
  2551.         clip {
  2552.             apex x y z      apex_radius r
  2553.             base x y z      base_radius r
  2554.             inside or outside
  2555.         }
  2556.     
  2557.  
  2558.          Just like the cone primitive you may also just define a
  2559.     single radius to get a cylinder. 
  2560.  
  2561.                     
  2562.  
  2563.          Sometimes you will want to apply the same clips to a group
  2564.     of primitives.  To do this define global clips using the
  2565.     global_clip keyword:
  2566.         global_clip {
  2567.             clip { ... }
  2568.             clip { ... }
  2569.             clip { ... }
  2570.         }
  2571.     
  2572.  
  2573.          The clip_pop keyword will cause the previous section of
  2574.     clips to be popped off the stack much like the transform_pop does
  2575.     for transformations. 
  2576.  
  2577.  
  2578.  
  2579.  
  2580.  
  2581.  
  2582.  
  2583.  
  2584.  
  2585.  
  2586.  
  2587.  
  2588.  
  2589.  
  2590.  
  2591.  
  2592.  
  2593.  
  2594.  
  2595.  
  2596.  
  2597.  
  2598.  
  2599.  
  2600.  
  2601.  
  2602.  
  2603.  
  2604.  
  2605.                     45
  2606.  
  2607.  
  2608.  
  2609.  
  2610.                 Support Programs
  2611.  
  2612.                    img2gif.exe
  2613.  
  2614.          Once vivid has completed an image you need some way to view
  2615.     the results.  That's where img2gif comes in.  Img2gif is used to
  2616.     convert the raw img file that Vivid outputs into a gif file.  The
  2617.     resulting gif file can then be viewed using your favorite view
  2618.     program.  My favorite is Brad Montgomery's vpic.  Look for it on
  2619.     you local BBS.  In a pinch, even fractint can be used to view
  2620.     gifs. 
  2621.  
  2622.          When running img2gif you have 2 main decisions to make: a)
  2623.     how should the program pick the palette and b) should the program
  2624.     do any dithering of the output.  Picking the palette is not
  2625.     always an easy problem.  Standard VGA allows us to view only 256
  2626.     of the available 262,144 colors.  An "average" lores image will
  2627.     have about 7000 colors which we need to represent with our
  2628.     palette of 256.  A higher resolution image my have tens of
  2629.     thousands of colors to represent.  The following algorithms are
  2630.     currently implemented in img2gif. 
  2631.  
  2632.          Palette File -- A palette may be input via a .map file. 
  2633.     This uses the same format as .map files created/read by fractint. 
  2634.     This option is useful for creating multiple gifs with the same
  2635.     palette for animation. 
  2636.  
  2637.          Popularity -- The popularity algorithm chooses the palette
  2638.     by picking the 256 colors which represent then greatest number of
  2639.     pixels in the image.  The remaining colors in the image are
  2640.     mapped onto the palette using a minimum distance formula.  The
  2641.     popularity algorithm tends to work best on images with a lower
  2642.     number of colors.  One typical problem of the algorithm is that
  2643.     small highlights may not be colored correctly.  Highlights
  2644.     generally only cover a few pixels so their color usually doesn't
  2645.     have enough representation in the image to be chosen by the
  2646.     popularity algorithm.  To help alleviate this problem, img2gif
  2647.     forces the corners of the color cube (white, red, green, blue,
  2648.     cyan, magenta, yellow, and black) to be selected as the first
  2649.     eight palette entries.  Since most highlights are white this
  2650.     greatly helps reduce unwanted artifacts in the resulting image. 
  2651.  
  2652.          Median Cut -- The median cut algorithm tries to choose a
  2653.     more well balanced set of colors to represent the image.  The
  2654.     general idea of the median cut is to choose a palette in which
  2655.     each entry represents about the same number of pixels in the
  2656.     image.  This helps to correctly color highlights that a pure
  2657.     popularity algorithm might miss.  Img2gif also allows you to
  2658.     limit the number of pixels represented by any one color.  This,
  2659.     in effect, increases the importance of the colors in highlights
  2660.     and other small regions of the image.  With this limit set to
  2661.     one, every color in the image is given the same weight without
  2662.  
  2663.                     46
  2664.  
  2665.  
  2666.  
  2667.     regard for the number of pixels it covers. 
  2668.  
  2669.          Fixed Palette -- The fixed palette option uses a
  2670.     predetermined palette instead of choosing one based on the
  2671.     content of the image.  This has the advantage of being much
  2672.     faster.  When choosing by popularity or median cut img2gif must
  2673.     first build a tree structure in memory containing every color in
  2674.     the image and a count of the number of pixels represented by that
  2675.     color.  After choosing the palette the colors in the tree must
  2676.     then be mapped onto the colors in the palette.  This can slow
  2677.     img2gif down quite a bit.  When using a fixed palette the image
  2678.     colors are mapped directly onto the palette colors via simple
  2679.     equations eliminating the need for the tree structure and the
  2680.     costly remapping of the images colors to an arbitrary palette. 
  2681.     Also, the current version of img2gif can only support a tree
  2682.     containing about 57,000 colors.  After this my clone runs out of
  2683.     RAM.  The fixed palettes supported by img2gif are:
  2684.  
  2685.          0 : A grey scale image using 256 grey scale tones.  Due to
  2686.     VGA limitations this will display as 64 shades on most PC
  2687.     systems. 
  2688.  
  2689.          1 : Divides the color cube into 8 shades of red, 8 shades of
  2690.     green, and 4 shades of blue.  Generally produces fairly bad
  2691.     images but kept in for nostalgia.  Blue was chosen to get the
  2692.     lower resolution because in general the human eye is much less
  2693.     sensitive in the blue range and has a harder time focusing on
  2694.     edges therefore the loss of color resolution is not missed as
  2695.     much. 
  2696.  
  2697.          2 : Divides the color cube into 6 shades of red, 7 shades of
  2698.     green, and 6 shades of blue.  This option gives the best balance
  2699.     of speed vs good color representation.  I've found that it works
  2700.     best with images that have a large number of colors.  The
  2701.     addition of dithering is usually helpful. 
  2702.  
  2703.          Dithering is the process of displaying pixels of differing
  2704.     colors next to each other in such a way as to produce the
  2705.     illusion of more colors.  An every day example of this is your
  2706.     television.  Stick your nose up to the picture tube and notice
  2707.     that the screen is made up of tiny red, green, and blue dots
  2708.     which vary in intensity.  These are the only colors your TV
  2709.     actually produces but your eye combines them to produce the rest
  2710.     of the spectrum.  Well, at least the spectrum according to NTSC. 
  2711.  
  2712.          Floyd Steinberg dithering is the original error diffusion
  2713.     dithering algorithm.  Error diffusion dithering attempts to
  2714.     compensate for a limited palette by insuring that the sum of the
  2715.     errors in any region of the image is zero even though the colors
  2716.     at each individual pixel may contain some error.  At each pixel
  2717.     as img2gif scans through the image the nearest color for that
  2718.     pixel is chosen.  Generally this color will not be exact.  The
  2719.     difference between the chosen palette color and the true color is
  2720.  
  2721.                     47
  2722.  
  2723.  
  2724.  
  2725.     then added to the neighboring pixels which have not been scanned
  2726.     yet.  Floyd Steinberg dithering has the advantage of having a
  2727.     "random" look to it.  Generally, it does not produce noticeable
  2728.     patterns in the output image. 
  2729.  
  2730.          Ordered dithering works by adding a fixed amount to each
  2731.     pixel based on its location.  The sum of these additions over a
  2732.     region of the image is equal to zero.  Since ordered dither does
  2733.     not take into account the values of neighboring pixels it
  2734.     produces fixed patterns in the images which may be distracting in
  2735.     some cases.  Ordered dithering combined with a fixed palette has
  2736.     an advantage if you are using Vivid to produce single fames for
  2737.     an animation.  During an animation the background (non-moving)
  2738.     regions of the image will stay constant whereas if you use Floyd
  2739.     Steinberg dithering the patterns constantly shift around and
  2740.     below any moving objects on the screen. 
  2741.  
  2742.          The random noise option allows you to add white noise to an
  2743.     image.  In some cases this may help as much as dithering.  It can
  2744.     also be used in conjunction with either of the dithering options. 
  2745.     Interesting effects may be obtained by increasing the range of
  2746.     the noise.  Images converted with a large amount of noise tend to
  2747.     take on a distinctly grainy look.  Interesting, but not overly
  2748.     useful.  The default range for the noise is +-8 on a 0..255
  2749.     range.  This value was chosen strictly because it seemed to look
  2750.     good in most cases.  Random noise has the advantage of being
  2751.     constant from image to image.  This means that smooth areas in a
  2752.     series of images will not shimmer during animation. 
  2753.  
  2754.          Ok, fine, now how do I run img2gif? Well, it goes like this:
  2755.  
  2756.          img2gif [-m #] [-f #] [-p palfile] [-d] [-o] [-r [#]] file
  2757.  
  2758.          The default palette choosing algorithm is the popularity
  2759.     method. 
  2760.  
  2761.          [-m #] chooses median cut and limits each color to represent
  2762.     at most # pixels.  # defaults to 64K. 
  2763.  
  2764.          [-f #] chooses fixed palette #.  # defaults to 0, grey
  2765.     scale. 
  2766.  
  2767.          [-p palfile] reads the palette out of the file palfile.map. 
  2768.     If this file does not exist the palette will be chosen by median
  2769.     cut, popularity, or fixed depending on what other flags are set. 
  2770.     After the palette is chosen it will then be written to the file
  2771.     palfile.map. 
  2772.  
  2773.          [-d] chooses Floyd Steinberg dithering. 
  2774.  
  2775.          [-o] chooses ordered dithering. 
  2776.  
  2777.          [-r #] chooses random noise +- #.  # defaults to 8. 
  2778.  
  2779.                     48
  2780.  
  2781.  
  2782.  
  2783.  
  2784.          For example:
  2785.  
  2786.          img2gif -f 2 -d test
  2787.  
  2788.          will convert test.img to test.gif using fixed palette 2 and
  2789.     Floyd Steinberg dithering. 
  2790.  
  2791.          Assuming that test.map does not exist
  2792.     
  2793.     img2gif -m -p test test1
  2794.     img2gif -m -p test test2
  2795.     img2gif -m -p test test3
  2796.     img2gif -m -p test test4
  2797.     
  2798.     will convert test1 using median cut to choose the palette.  The
  2799.     palette will then be saved to test.map.  Test2, test3, and test4
  2800.     will then be converted using the palette in test.map. 
  2801.  
  2802.          In general the best results will be obtained by using the -m
  2803.     -d flags as in img2gif -m -d test.  For images that tend to be
  2804.     fairly monochromatic I've found that -m -d -r 4 works well. 
  2805.     Adding the small amount of random noise helps break up some of
  2806.     the banding.  On the down side it also adds to the .gif file size
  2807.     since it is tough to compress random noise well.  To get nice
  2808.     looking grey scale images try -f 0 -r. 
  2809.  
  2810.  
  2811.  
  2812.  
  2813.  
  2814.  
  2815.  
  2816.  
  2817.  
  2818.  
  2819.  
  2820.  
  2821.  
  2822.  
  2823.  
  2824.  
  2825.  
  2826.  
  2827.  
  2828.  
  2829.  
  2830.  
  2831.  
  2832.  
  2833.  
  2834.  
  2835.  
  2836.  
  2837.                     49
  2838.  
  2839.  
  2840.  
  2841.  
  2842.                     paste.exe
  2843.  
  2844.          The paste tool will allow you to join together two images in
  2845.     raw file format either vertically (one over the other) or
  2846.     horizontally (side by side), ie.  two 320x200 images may be
  2847.     joined together to form a 320x400 image or a 640x200 image.  In
  2848.     order for two images to be joined vertically the images must have
  2849.     the same width.  In order for them to be joined horizontally they
  2850.     must have the same height. 
  2851.  
  2852.          The calling sequence for paste is:
  2853.  
  2854.          paste [-h | -v] in_file1.img in_file2.img out_file.img
  2855.  
  2856.          In the horizontal case in_file1.img will appear to the right
  2857.     of in_file2.img.  In the vertical case in_file1.img will appear
  2858.     above in_file2.img. 
  2859.  
  2860.  
  2861.  
  2862.  
  2863.  
  2864.  
  2865.  
  2866.  
  2867.  
  2868.  
  2869.  
  2870.  
  2871.  
  2872.  
  2873.  
  2874.  
  2875.  
  2876.  
  2877.  
  2878.  
  2879.  
  2880.  
  2881.  
  2882.  
  2883.  
  2884.  
  2885.  
  2886.  
  2887.  
  2888.  
  2889.  
  2890.  
  2891.  
  2892.  
  2893.  
  2894.  
  2895.                     50
  2896.  
  2897.  
  2898.  
  2899.  
  2900.                      up.exe
  2901.  
  2902.          Up allows you to double an image's size vertically,
  2903.     horizontally, or in both directions.  The increase in size is
  2904.     done by pixel duplication, no interpolation is used.  The calling
  2905.     sequence is:
  2906.  
  2907.          up [-h | -v] in_file.img out_file.img
  2908.  
  2909.          If no flag is given, up increases the image's size in both
  2910.     directions. 
  2911.  
  2912.          For example if test.img is a 320x200 image
  2913.  
  2914.          up -v test.img test2.img
  2915.  
  2916.          will create test2.img with a resolution of 320x400. 
  2917.  
  2918.  
  2919.  
  2920.  
  2921.  
  2922.  
  2923.  
  2924.  
  2925.  
  2926.  
  2927.  
  2928.  
  2929.  
  2930.  
  2931.  
  2932.  
  2933.  
  2934.  
  2935.  
  2936.  
  2937.  
  2938.  
  2939.  
  2940.  
  2941.  
  2942.  
  2943.  
  2944.  
  2945.  
  2946.  
  2947.  
  2948.  
  2949.  
  2950.  
  2951.  
  2952.  
  2953.                     51
  2954.  
  2955.  
  2956.  
  2957.  
  2958.                     down.exe
  2959.  
  2960.          Down does the opposite of up.  (surprise!) When reducing an
  2961.     image's size, down averages the appropriate pixels to produce the
  2962.     new pixel.  The calling sequence is:
  2963.  
  2964.          down [-h | -v] infile.img outfile.img
  2965.  
  2966.          If no flag is given, down reduces the image in both
  2967.     directions. 
  2968.  
  2969.          For example if test is a 320x200 image
  2970.  
  2971.          down test.img test2.img
  2972.  
  2973.          will produce test2.img with a resolution of 160x100. 
  2974.  
  2975.  
  2976.  
  2977.  
  2978.  
  2979.  
  2980.  
  2981.  
  2982.  
  2983.  
  2984.  
  2985.  
  2986.  
  2987.  
  2988.  
  2989.  
  2990.  
  2991.  
  2992.  
  2993.  
  2994.  
  2995.  
  2996.  
  2997.  
  2998.  
  2999.  
  3000.  
  3001.  
  3002.  
  3003.  
  3004.  
  3005.  
  3006.  
  3007.  
  3008.  
  3009.  
  3010.  
  3011.                     52
  3012.  
  3013.  
  3014.  
  3015.  
  3016.                   File Formats
  3017.  
  3018.  
  3019.          The information included here about the file formats is to
  3020.     aid people in writing their own image manipulation utilities
  3021.     compatible with the Vivid formats.  I encourage you to experiment
  3022.     and share any interesting results with the rest of us. 
  3023.  
  3024.          img -- This is the format of the files output by Vivid.  The
  3025.     images are stored 24-bits per pixel with a simple run length
  3026.     encoding scheme to help keep the size down.  The run length
  3027.     encoding works by replacing a repetitive string of the same color
  3028.     with a count value and that color written only once.  "Runs" of
  3029.     the same color are not allowed to continue beyond the end of the
  3030.     scanline to make working a scanline at a time easier.  The format
  3031.     consists of a 10 byte header followed by the image data.  The
  3032.     16-bit numbers in the header are stored most significant byte
  3033.     first.  This format is compatible with that used by Alias
  3034.     Research.  (I think.)
  3035.     
  3036.     <2-bytes>       x size of image
  3037.     <2-bytes>       y size of image
  3038.     <2-bytes>       first scanline, usually 0
  3039.     <2-bytes>       last scanline, usually y size - 1
  3040.     <2-bytes>       number of bitplanes, always 24
  3041.     <image data>
  3042.     
  3043.     The image data format looks like:
  3044.     
  3045.     <1-byte>        a repeat count for the following color
  3046.     <1-byte>        blue, 0..225
  3047.     <1-byte>        green, 0..255
  3048.     <1-byte>        red, 0..255
  3049.     
  3050.     This is repeated as many times as necessary to complete the
  3051.     image.  Note: runs do not wrap from one scan line to the next. 
  3052.     This helps simplify post-processing.  It has been noted (hi Ray!)
  3053.     that in some of Vivid's antialiasing modes an extra scan line is
  3054.     output to the file.  This may eventually get fixed but for now
  3055.     the best thing to do is to always use the info in the header
  3056.     rather than looking for the end of file. 
  3057.  
  3058.          map -- This is the format used for palette files.  This
  3059.     format was chosen to be compatible with fractint.  The file is in
  3060.     plain ASCII text and consists of 256 lines each containing the
  3061.     red, green and blue value for that palette entry.  The rgb values
  3062.     are integers in the range 0..255. 
  3063.  
  3064.  
  3065.  
  3066.  
  3067.  
  3068.  
  3069.                     53
  3070.  
  3071.  
  3072.  
  3073.  
  3074.                   Bibliography
  3075.  
  3076.  
  3077.          For anyone interested in ray tracing and how it works the
  3078.     following books are highly recommended.  Further references may
  3079.     be found in the bibliography at the end of Glassner's book. 
  3080.  
  3081.          "Computer Graphics, Principles and Practice, 2nd Ed.",
  3082.     Foley, van Dam, Feiner and Hughes, 1990, ISBN 0-201-12110-7
  3083.  
  3084.          "An Introduction to Ray Tracing", Andrew S.  Glassner, ed.,
  3085.     Academic Press, 1989, ISBN 0-12-286160-4
  3086.  
  3087.          "Illumination and Color in Computer Generated Imagery", Roy
  3088.     Hall, Springer-Verlag, 1989, ISBN 0-387-96774-5
  3089.  
  3090.  
  3091.  
  3092.  
  3093.  
  3094.  
  3095.  
  3096.  
  3097.  
  3098.  
  3099.  
  3100.  
  3101.  
  3102.  
  3103.  
  3104.  
  3105.  
  3106.  
  3107.  
  3108.  
  3109.  
  3110.  
  3111.  
  3112.  
  3113.  
  3114.  
  3115.  
  3116.  
  3117.  
  3118.  
  3119.  
  3120.  
  3121.  
  3122.  
  3123.  
  3124.  
  3125.  
  3126.  
  3127.                     54
  3128.  
  3129.  
  3130.  
  3131.  
  3132.                       Index
  3133.  
  3134.           #define. . . . . . . . . . . . . . . . . . . . .  15
  3135.           #include . . . . . . . . . . . . . . . . . . . 5, 16
  3136.           ambient. . . . . . . . . . . . . . . . . . . . .  19
  3137.           angle. . . . . . . . . . . . . . . . . . . . . .  17
  3138.           antialiasing . . . . . . . . . . . . . . . . . .  20
  3139.           aperture . . . . . . . . . . . . . . . . . . . .  21
  3140.           aspect ratio . . . . . . . . . . . . . . . . . .  18
  3141.           at . . . . . . . . . . . . . . . . . . . . . . .  17
  3142.           background color . . . . . . . . . . . . . . . .  19
  3143.           bibliography . . . . . . . . . . . . . . . . . .  54
  3144.           blend. . . . . . . . . . . . . . . . . . . . . .  34
  3145.           bump mapping . . . . . . . . . . . . . . . . . .  31
  3146.           bunching . . . . . . . . . . . . . . . . . . . .  22
  3147.           caustics . . . . . . . . . . . . . . . . . . . .  22
  3148.           changes for 2.0. . . . . . . . . . . . . . . . .   3
  3149.           checker pattern. . . . . . . . . . . . . . . . .  33
  3150.           clipping . . . . . . . . . . . . . . . . . . . .  44
  3151.           clipping plane . . . . . . . . . . . . . . . . .  44
  3152.           colors . . . . . . . . . . . . . . . . . . . . .  13
  3153.           command line flags . . . . . . . . . . . . . . .   6
  3154.           comments . . . . . . . . . . . . . . . . . . . .  14
  3155.           compound surfaces. . . . . . . . . . . . . . . .  33
  3156.           cone . . . . . . . . . . . . . . . . . . . . . .  41
  3157.           coordinate system. . . . . . . . . . . . . . . .  13
  3158.           depth. . . . . . . . . . . . . . . . . . . . . .  22
  3159.           dithering. . . . . . . . . . . . . . . . . . . .  47
  3160.           down.exe . . . . . . . . . . . . . . . . . . . .  52
  3161.           field of view angle. . . . . . . . . . . . . . .  17
  3162.           file extensions. . . . . . . . . . . . . . . . .   5
  3163.           file formats . . . . . . . . . . . . . . . . . .  53
  3164.           fixed palettes . . . . . . . . . . . . . . . . .  47
  3165.           Floyd Steinberg dithering. . . . . . . . . . . .  47
  3166.           focal_length . . . . . . . . . . . . . . . . . .  21
  3167.           from . . . . . . . . . . . . . . . . . . . . . .  17
  3168.           fuzz . . . . . . . . . . . . . . . . . . . . . .  34
  3169.           gif. . . . . . . . . . . . . . . . . . . . . . .  46
  3170.           global clipping. . . . . . . . . . . . . . . . .  45
  3171.           haze . . . . . . . . . . . . . . . . . . . . . .  19
  3172.           img file format. . . . . . . . . . . . . . . . .  53
  3173.           img2gif.exe. . . . . . . . . . . . . . . . . . .  46
  3174.           include files. . . . . . . . . . . . . . . . . .   5
  3175.           input file format. . . . . . . . . . . . . . . .  13
  3176.           jitter . . . . . . . . . . . . . . . . . . . . .  21
  3177.           lights . . . . . . . . . . . . . . . . . . . . .  24
  3178.              directional . . . . . . . . . . . . . . .  24
  3179.              point . . . . . . . . . . . . . . . . . .  24
  3180.              spherical . . . . . . . . . . . . . . . .  25
  3181.              spot. . . . . . . . . . . . . . . . . . .  25
  3182.           macro. . . . . . . . . . . . . . . . . . . . . .  15
  3183.           macro continuation . . . . . . . . . . . . . . .  15
  3184.  
  3185.                     55
  3186.  
  3187.  
  3188.  
  3189.           mandelbrot . . . . . . . . . . . . . . . . . . .  36
  3190.           map file format. . . . . . . . . . . . . . . . .  53
  3191.           median cut algorithm . . . . . . . . . . . . . .  46
  3192.           noise. . . . . . . . . . . . . . . . . . . . . .  34
  3193.           no_antialias . . . . . . . . . . . . . . . . . .  29
  3194.           no_exp_trans . . . . . . . . . . . . . . . . . .  21
  3195.           no_shadows . . . . . . . . . . . . . . . . . . .  21
  3196.           ordered dither . . . . . . . . . . . . . . . . .  48
  3197.           palette file . . . . . . . . . . . . . . . . . .  46
  3198.           paste.exe. . . . . . . . . . . . . . . . . . . .  50
  3199.           polygon. . . . . . . . . . . . . . . . . . . . .  39
  3200.           popularity algorithm . . . . . . . . . . . . . .  46
  3201.           preprocessor . . . . . . . . . . . . . . . . . .  15
  3202.           projection . . . . . . . . . . . . . . . . . . .  18
  3203.           random noise dithering . . . . . . . . . . . . .  48
  3204.           resolution . . . . . . . . . . . . . . . . . . .  18
  3205.           resume . . . . . . . . . . . . . . . . . . . . .   6
  3206.           right-handed coordinate system . . . . . . . . .  13
  3207.           ring . . . . . . . . . . . . . . . . . . . . . .  38
  3208.           samples. . . . . . . . . . . . . . . . . . . . .  21
  3209.           solid texture. . . . . . . . . . . . . . . . . .  33
  3210.           sphere . . . . . . . . . . . . . . . . . . . . .  37
  3211.           spherical pattern. . . . . . . . . . . . . . . .  33
  3212.           start. . . . . . . . . . . . . . . . . . . . . .  18
  3213.           statistics . . . . . . . . . . . . . . . . . . .   7
  3214.           stop . . . . . . . . . . . . . . . . . . . . . .  18
  3215.           studio . . . . . . . . . . . . . . . . . . . . .  17
  3216.           surfaces . . . . . . . . . . . . . . . . . . . .  28
  3217.           threshold. . . . . . . . . . . . . . . . . . . .  20
  3218.           transform. . . . . . . . . . . . . . . . . . . .  42
  3219.           transform_pop. . . . . . . . . . . . . . . . . .  42
  3220.           triangular patch . . . . . . . . . . . . . . . .  40
  3221.           turbulence . . . . . . . . . . . . . . . . .  32, 34
  3222.           up . . . . . . . . . . . . . . . . . . . . . . .  17
  3223.           up.exe . . . . . . . . . . . . . . . . . . . . .  51
  3224.           viewpoint. . . . . . . . . . . . . . . . . . . .  17
  3225.           wave bump map. . . . . . . . . . . . . . . . . .  31
  3226.           xyzzy.v. . . . . . . . . . . . . . . . . . . . 5, 15
  3227.  
  3228.